Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pagination sql query syntax

I am trying to sort my posts in my discussion board by date. Here is my code:

$query = mysql_query("SELECT * FROM {$statement} 
LIMIT {$startpoint} , {$limit} 
ORDER BY datetime ASC");

Is there anything syntactically wrong with this? If not, what else could be wrong? Basically what is happening, is that the results are not showing up. I remove the Order by, and it works (but of course it's not sorted...)

like image 358
droidus Avatar asked Aug 20 '26 13:08

droidus


1 Answers

Order by should go before limit:

$query = mysql_query("SELECT * FROM {$statement} 
ORDER BY datetime ASC LIMIT {$startpoint} , {$limit}");
like image 171
Eugene Retunsky Avatar answered Aug 23 '26 03:08

Eugene Retunsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!