PHP MySQL - DESC LIMIT禁用ORDER BY

时间:2015-10-29 13:06:35

标签: php mysql sql-order-by

我是MySQL的新手,我正在尝试按日期订购消息。我还希望显示不超过10条消息。我的问题:

$sql2 = "SELECT `id`, `Afbeelding`, `Vraag`, DATE_FORMAT(date, '%d-%m-%Y %H:%i:%s') FROM vraagstellen ORDER BY date DESC LIMIT 10";

订单被禁用。谁可以帮助我?谢谢!

3 个答案:

答案 0 :(得分:0)

试试这个

$sql2 = "SELECT `id`, `Afbeelding`, `Vraag`, DATE_FORMAT(date, '%d-%m-%Y %H:%i:%s') as date_formatted FROM vraagstellen ORDER BY date DESC LIMIT 10";

您的代码:

$sql2 = "SELECT `id`, `Afbeelding`, `Vraag`, DATE_FORMAT(date, '%d-%m-%Y %H:%i:%s') FROM vraagstellen ORDER BY date DISC LIMIT 10";
  • DISC - > DESC
  • 添加了as date_formatted

答案 1 :(得分:0)

更改

ORDER BY date DISC

ORDER BY date DESC

答案 2 :(得分:0)

将DISC更改为DESC

尝试使用:ORDER BY date DESC LIMIT 10

$sql2 = "SELECT id, Afbeelding, Vraag, DATE_FORMAT(date, '%d-%m-%Y %H:%i:%s') as newdate FROM vraagstellen ORDER BY newdate DESC LIMIT 10";

现在使用date

访问newdate字段