PHP Echo $ info按降序排列

时间:2012-05-21 12:47:35

标签: php mysql database

好的,我的数据库名为'posts'

有6个字段

postid, title, message, date, time, day

每当我打印出每一行时,它都会向上打印出来?

表格

postid | 标题 |的消息

00001 | ........ | ........

<00> 00002 | ........ | ........

<00> 00003 | ........ | ........

当我打印出来时,就像

00001, ..., ...
00002, ..., ...
00003, ..., ...

但我想要

0003, ..., ...
0002, ..., ...
0001, ..., ...

有办法吗?我在谷歌找不到它......不管怎样,提前谢谢:)

6 个答案:

答案 0 :(得分:4)

SELECT `postid`, `title`, `message`, `date`, `time`, `day`
FROM `table1`
ORDER BY `postid` DESC;

答案 1 :(得分:2)

试试这个,

select reverse(substr(reverse(postid), 1, 4)) as postid, title, message, date, time, day from posts order by postid desc;

假设您希望输出为4位而不是5

答案 2 :(得分:0)

将此附加到您的查询中:

ORDER BY `postid` DESC

它会按降序排序,而不是按升序排序。

答案 3 :(得分:0)

你可以试试这个 -

SELECT `postid`, `title`, `message`, `date`, `time`, `day`
FROM `tablename`
ORDER BY `postid` DESC;

你也可以

SELECT CONCAT(`postid`, ',', `title`, ',',  `message`, ',', `date`, ',', `time`, ',', `day`)
FROM `tablename`
ORDER BY `postid` DESC;

答案 4 :(得分:0)

执行查询,例如SELECT postid, title, message, date, time, day FROM表格ORDER BY postid DESC

答案 5 :(得分:0)

只需使用ORDER BY功能。

SELECT * FROM your_table ORDER BY postid DESC

DESC关键字只是颠倒了订单。