简体   繁体   中英

Order mysql query with php

I want to order my posts from mysql. Newest at first.

Whit this code working fine, but oldest posts at first place

$sql = "SELECT * FROM post LIMIT $offset, $no_of_records_per_page";

////////////

I tried with this codes and i got an error " mysqli_fetch_object() expects parameter 1 to be mysqli_result, bool given"

$sql = "SELECT * FROM post LIMIT $offset, $no_of_records_per_page DESC";

or

$sql = "SELECT * FROM post LIMIT $offset, $no_of_records_per_page ORDER BY date DESC";

Im using pagination. How can i slove this?

The row-limiting syntax is ORDER BY ... LIMIT ... .

So:

SELECT * FROM post ORDER BY date DESC LIMIT $offset, $no_of_records_per_page;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM