I have a dynamic mysql query, and the ORDER BY part is hard-coded into the query.
Problem is, I don't know if every query will have an ORDER BY, nor do I know which columns will be available to order by.
Is there a default value I can write, so that I can use
if (empty($order)){$order = "default_value"}
$query = "select ...... ORDER BY $order"
There is no default order to results from queries. If you don't explicitly specify an ORDER BY clause, the data order is undefined. You can only specify ASC DESC and some columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With