ok this is not smf related but I needs help (imagine that) and my normal go to guy isn't responding
how can I write an if statement or else statement for order by
WHERE collections_post.collection_id = "' . $Listing['id'] . '"
GROUP BY posts.id
ORDER BY collections_post.sortable ASC'
)->all();
I need it to order by sortable else if null order by create year
ORDER BY collections_post.sortable ASC'
else
ORDER BY posts.create_year DESC'
Make $order_by a variable. If using $smcFunc, pass the value in the array.
The query is just a string & can be manipulated at will! :)
:laugh: :laugh: :laugh: :laugh: was that even english
sorry but yeah ya lost me...I've no clue what I'm doing here and I tried to google it but came up empty
this at least doesn't give me any errors, but it also doesn't work
ORDER BY
CASE WHEN collections_post.sortable = !NULL THEN collections_post.sortable END ASC,
CASE WHEN collections_post.sortable = NULL THEN posts.create_year END DESC'
[edit]
I think I figured it out, seems to be working
ORDER BY
CASE WHEN collections_post.sortable IS NULL THEN posts.create_year
ELSE collections_post.sortable END ASC'
Thank you
If you're using a GROUP BY clause, then you need to be aware of MySQL's "GROUP BY strict mode"
https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html