mohsin_sharif57 mohsin_sharif57 - 2 months ago 5x
MySQL Question

Query gives error when using order by with limit clause

I am using this query for fetching data from database. its working fine.

$sql = "SELECT * FROM videos LIMIT $page1,5 ";

But I want to apply order by clause in this query. When I run this query

$sql = "SELECT * FROM videos ORDER BY desc LIMIT $page1,5 ";

it gives error:

: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:
Syntax error or access violation:

I don't understand on which point I did wrong. Please help me. Thanks!


You are missing a column name for your ORDER BY clause.

$sql = "SELECT * FROM videos ORDER BY COLUMNAME_GOES_HERE desc  LIMIT $page1,5 ";