Ugleh Ugleh - 1 year ago 97
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.

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download