Sort Order By

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

Re: [jdancisin] Sort Order By

By zip222 - April 3, 2009

Through a little trial and error, it seems like a sort using numbers works like an alphabetical sort. It groups all values starting with "1", and then determines the order of the "1" values by the second character. As opposed to sorting the list by the full value of the number.

Is this standard behavior? Is there a way around this?

Re: [jdancisin] Sort Order By

By zip222 - April 3, 2009

Figured it out!

By changing my sort order to this...
date_awarded DESC, category, (grant_amount+0) DESC, title

The numbers are now seen as numbers rather than characters. Cool!

If someone knows another solution to this, I would be interested in knowing what it is.

Re: [jdancisin] Sort Order By

By Dave - April 3, 2009

Hi jdancisin,

The simplest is to just add +0 when sorting, but a more advanced option would be to set the field to be a numeric column type in mysql. You can do that under: Admin > Section Editors > Your Section > Your Field > Advanced > Mysql Column Type

Depending on your content you might want INT or FLOAT. You can see a list of column types here:
http://help.scibit.com/Mascon/masconMySQL_Field_Types.html

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Sort Order By

By zip222 - May 14, 2009

I need to bring this post back up because there is still an issue...

I am ordering by a field that contains a number and it works fine as long as all of the numbers are between 1,000 and 999,000. But I have a few numbers that are outside that range and they aren't ordering properly. I am thinking I may need to use the mySQL column type to get this to work properly.

Help? Thoughts?

Re: [jdancisin] Sort Order By

By ross - May 15, 2009

Hi there.

Would you mind sending me an email with FTP details to your site through consulting@interactivetools.com. Also put a link to this thread in there so I know what I need to look for :).

I would like to take a closer look at how you have all this setup. My first thought is that perhaps the data format is the problem. The best case is to always enter your numbers without any formatting. So you would use 1000 instead of 1,000.

Let me know what you think and send those details when you can.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Sort Order By

By zip222 - May 15, 2009

Information has been sent. Thanks for you help.

Re: [Dave] Sort Order By

By Toledoh - November 3, 2011

When I try to do this, I get an error pop-up.

There was an error changing the MySQL Column, the error was:

Incorrect integer value: '' for column 'price' at row 16

See attached.
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Sort Order By

By Dave - November 3, 2011

Hi Tim,

You can't have blank values for INT fields, you need to default everything to zero ("0"). Is there an easy way you can update the records with a blank price to be 0 instead?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Sort Order By

By Toledoh - November 3, 2011

I've used 'orderBy' =>'(price +0) DESC', and this is doing the trick, so I'll stick with that.

Thanks Dave
Cheers,

Tim (toledoh.com.au)