Sort records by the sort order in another table

3 posts by 3 authors in: Forums > CMS Builder
Last Post: August 13, 2013   (RSS)

By benedict - August 12, 2013

So here's a curly one. The CMS has a Wine Varieties (cms_varieties) and a Wines (cms_wines) section. The varieties are linked into the Wines section via a list field.

Now, I the customer wants the wines sorted by variety - these are not sorted alphabetically, rather by the strength of the grape from white through to red wines. So I'm using DragSortOrder in the varieties table - on the wines list viewer page  how do I get the wines to order by the variety order from the variety table, i.e. not alphabetically.  ?

Hi benedict,

Would it be possible to post or attach the code you've already created? I think you need to use the array_groupBy function:

$yourArray = ksort(array_groupBy($yourArray, 'dragSortOrder'));

This function would make the array key the dragSortOrder field, and you could then sort the array on this field using the ksort function.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com