简体   繁体   English

用php命令mysql查询

[英]Order mysql query with php

I want to order my posts from mysql.我想从 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"我尝试使用此代码,但出现错误“mysqli_fetch_object() 期望参数 1 为 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 ... .行限制语法是ORDER BY ... LIMIT ...

So:所以:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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