Sorting

2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 4, 2014   (RSS)

By gregThomas - March 4, 2014

Hi nmsinc,

I've done some research and it's possible to sort by the last word in a string in a field like this:

  'orderBy'     => "substring_index(name, ' ', -1) "

So in this case the field I'm using is name. It works by breaking up the name field into an array separated on the space character, getting the last element from the array, and sorting on it.

I'd highly recommend creating separate first name/last name/ title fields. This will make the data a lot easier to manage, and any queries you make on the data much faster. 

Let me know if you have any questions.

Thanks!

Greg 

Greg Thomas







PHP Programmer - interactivetools.com