Sorting List Views by Integer Values
8 posts by 3 authors in: Forums > CMS Builder
Last Post: July 13, 2012 (RSS)
By InHouse - July 11, 2012
J.
Re: [InHouse] Sorting List Views by Integer Values
By gkornbluth - July 11, 2012
Could you add the zero and then if they must be removed for viewers, strip them with a preg_replace?
Or, this may give you some ideas...
http://stackoverflow.com/questions/5511393/how-to-sort-1-11-12-2-all-others-to-all-1-2-11-12-others
Or... Maybe Jason will have a magical solution to this.
Best,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Sorting List Views by Integer Values
By InHouse - July 12, 2012
i.e.:
Ordered QTY Column
11
12
1
2
3
etc...
Not quite what was expected - though very familiar to people born before 1984. ;-)
J.
Re: [InHouse] Sorting List Views by Integer Values
By gkornbluth - July 12, 2012
Hope this will prompt a fix.
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [InHouse] Sorting List Views by Integer Values
By Jason - July 12, 2012
The best solution here is to actually make the field a numeric field. By default all text fields in CMS Builder are stored as mySQL strings. If you edit a field, under Advanced Options, you'll see "MySQL Column Type". In your example, you can give your field a mysql field type of "INT". This should take care of the sorting issues. (Remember to backup first).
For more information about mysql numeric types, see here:
http://dev.mysql.com/doc/refman/5.5/en/numeric-types.html
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/
Re: [Jason] Sorting List Views by Integer Values
By InHouse - July 13, 2012
Sadly though, when I tried it (after backing up of course ;-) ) the following error gets thrown:
There was an error changing the MySQL Column, the error was:
Incorrect integer value: '' for column 'qty' at row 133
Not sure where to take it from there. Running CMSB v.2.15.
Re: [InHouse] Sorting List Views by Integer Values
By Jason - July 13, 2012
What's happening is that when you change the column type, mySQL attempts to convert each value in that field to the new data type. In your case, there is one (or more) records where qty has an empty string as a value, which cannot be converted. For any record without a value for qty, trying putting in a 0. Once all qty fields have an integer value, try changing the column again.
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/
Re: [Jason] Sorting List Views by Integer Values
By InHouse - July 13, 2012
Many thanks, Jason.