Just a thought… instead of trying to force your type into doubling as a sort-order field, why not create a sort-order table that maps types to sort order? Then you can join on that pretty painlessly and sort using those values. That would seem like a much less "tricky" solution that would cause less surprises in the long run, and make it so you don't have to create ever-more-complicated query modifications when you want to change the sort order or when you add new types.
Jenn On Jun 4, 2013, at 9:18 PM, Wade Shearer <[email protected]> wrote: > Thanks for the idea of using a union. I'm not sure why I hadn't tried that. I > cleaned things up tremendously. I'm now getting the data in a single query > and doing the sorting as part of the query. > > Thanks, Chris, for reminding me about the trick to create a temporary sort > value with IF(). > > > On 4 Jun 2013, at 9:29, Steve Meyers <[email protected]> wrote: > >> On 6/4/13 8:11 AM, Wade Shearer wrote: >>> The reason that I can't do the sort in the SQL is because I am make >>> four queries and then merging them first. >> >> Can't you do a UNION, and then sort that? If you post (or send me) your >> four queries, I can show you how to do it all in a single query including >> the sort. >> >> If you really want to do it in the PHP code, I'd try this: >> >> usort($all, function($a, $b) { >> $a_sort = ($a['type'] == 3 ? 6 : intval($a['type'])); >> $b_sort = ($b['type'] == 3 ? 6 : intval($b['type'])); >> if ($a_sort == $b_sort) return 0; >> return ($a_sort < $b_sort) ? -1 : 1; >> } > > > _______________________________________________ > > UPHPU mailing list > [email protected] > http://uphpu.org/mailman/listinfo/uphpu > IRC: #uphpu on irc.freenode.net _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
