按日期排序(最新) [英] Sort by date (newest)

查看:64
本文介绍了按日期排序(最新)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在使用下面的查询按每篇文章的 auto_increment id 进行排序

Right now I'm sorting by each articles auto_increment id with the query below

mysql_query("SELECT * FROM articles ORDER BY id DESC");

我想知道如何按我创建的日期字段进行排序,该字段通过 strtotime() 存储当前日期,它应该查询从最新到最旧的日期.

I want to 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

这篇关于按日期排序(最新)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆