Ugleh Ugleh - 1 month ago 7
MySQL Question

PHP Order By not working

Here is my PHP Query, but it doesn't seem to order the results. Everything else works fine.

SELECT *
FROM `main`
WHERE `user_legacy` LIKE '%".$name."%'
ORDER BY 'user_legacy' DESC LIMIT ".$limit

Answer

You use backticks (') to quote column names in SQL, not the normal single quote (').

ORDER BY `user_legacy` DESC

Also, if you don't do any kind of vetting or your input, that query is potentially vulnerable to an SQL injection.