Zend Framework, Zend_Db_Table ORDER BY sorting NULL as last instead of first
If you have a group of fields, some of which may be null (such as an address, in which the 1st line of the address may or may not be filled in) then you may want to sort them all so that if null appears in a field, it’s sorted to the bottom of the list as opposed to the top (which is the default behaviour)
$select = $table->select();
$rowset = $table->fetchAll($select->order('IF(ISNULL(line1),1,0), line1', 'line2', 'city', 'country'));
I grabbed the MySQL code from the MySQL Forums
Leave a comment
Categories
- Been knackered for days on end, long day with relatives today then most of tomorrow in the office doing downtime maintenance. I should rest!
- Dinner with my mom, couz and uncle (@ Gold Mine) http://t.co/pj4iA2Ul
- Om nom nom http://t.co/Kd2CIzs9
- I'm at Westfield London Shopping Centre (Shepherd's Bush, Greater London) w/ 13 others http://t.co/b2kCzQOG
- Off to see relatives (@ Northampton Railway Station (NMP) w/ 2 others) http://t.co/3ekCATN8
Recent Posts
- Use Zend_Log_Writer_Firebug to debug AJAX requests using Firebug
- Using Zend_Db_Profiler_Firebug to show database queries per page
- Checking $mixed parameter type for PHP methods
- “concrete5 cannot parse the PATH_INFO or ORIG_PATH_INFO information provided by your server.”
- Enable hibernation on HP MicroServer for Windows Home Server v1




