Sort by 2 fields

4 posts by 3 authors in: Forums > CMS Builder
Last Post: July 11, 2012   (RSS)

Hi

Any ideas how I can sort by 2 different fields. I need to sort by 'building' first, then 'unit_no', but it's coming back with the unit numbers in this order

F14
F8
F35
F39
F707
...when they need to be sequential.
I've tried this code 'orderBy' => 'building','unit_no' ,
but it's not working. Any ideas?
thanks

Re: [gkornbluth] Sort by 2 fields

Thanks, tried that, but it still doesn't work?

Re: [degreesnorth] Sort by 2 fields

By Jason - July 11, 2012

Hi,

The problem here is that your unit numbers (ie F14, F8, etc) are strings and are being sorted alphabetically. MySQL cannot tell that this is a letter followed by a number. The easiest solution here, would be to store your unit numbers as actual numbers (ie, 14, 8, etc) and then sort. If you need the "F", you could have a field for unit_number_prefix and you can output in front of the number for display.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/