php mysql按日期排序(最新) [英] php mysql sort by date (newest)
本文介绍了php mysql按日期排序(最新)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,即时消息通过以下查询按每篇文章的auto_increment ID进行排序
Right now im sorting by each articles auto_increment id with the query below
mysql_query("SELECT * FROM articles ORDER BY id DESC");
mysql_query("SELECT * FROM articles ORDER BY id DESC");
我想知道如何按我创建的日期字段排序,该字段通过strtotime()存储当前日期,它应该查询从最新到最早的日期.
I wanna know how to sort by a date field i made, that stores the current date via, strtotime() it should query the dates from newest to oldest.
当前代码
$alist = mysql_query("SELECT * FROM articles ORDER BY id DESC");
$results = mysql_num_rows($alist);
if ($results > 0){
while($info = mysql_fetch_array($alist)) {
// query stuff
echo $info['time'];
}
推荐答案
只需更改ORDER BY中的列:
Just change the column in the ORDER BY:
SELECT * FROM articles ORDER BY time DESC
这篇关于php mysql按日期排序(最新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文