php mysql sort by date (newest)

后端 未结 2 648
南笙
南笙 2020-12-03 11:34

Right now im sorting by each articles auto_increment id with the query below

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

I wanna

相关标签:
2条回答
  • 2020-12-03 12:12

    Just change the column in the ORDER BY:

    SELECT * FROM articles ORDER BY time DESC
    
    0 讨论(0)
  • 2020-12-03 12:35

    Let MySQL handle the date stuff - IMO its MUCH better at it than PHP...

    add a column with DATE or DATETIME type in your table. On inserting a new record either use NOW() or set a trigger to do it for you (will have to allow null in the coulmn if you are going to user a trigger)

    your query should be:

    $alist = mysql_query("SELECT * FROM articles ORDER BY `your_date_field` DESC");
    
    0 讨论(0)
提交回复
热议问题