PHP/MySQL从Order语句中选择,结果不正确

时间:2021-09-23 22:48:29

Anybody have any idea why this query isn't working?

有人知道为什么这个查询不能工作吗?

$result = mysql_query("SELECT * FROM Events ORDER BY ID ASC LIMIT 0, 10");

I want the data to order backwards, from the highest value ID all the way to 1.

我想要数据的顺序从最高的ID一直到1。

But it doesn't do that. It just orders them 1,2,3,4,5

但它不会这么做。它只给它们1 2 3 4 5

Any help is greatly appreciated.

非常感谢您的帮助。

6 个解决方案

#1


2  

You are sorting in ASCending order when you want to sort in DESCending order. Try the following instead:

当你想按降序排序时,你是按升序排序。试试以下:

$result = mysql_query("SELECT * FROM Events ORDER BY ID DESC LIMIT 0, 10");

If per chance, you want the 10 items with the lowest ID's but want them in descending order, then you could use the following:

如果您希望10个具有最低ID的项按降序排列,那么您可以使用以下方法:

$result = mysql_query("SELECT * FROM (SELECT * FROM Events ORDER BY ID ASC LIMIT 0, 10) ORDER BY ID DESC");

#2


2  

Pretty simple.

很简单。

ORDER BY ID DESC

(ASC means ascending, DESC means descending).

(ASC表示上升,DESC表示下降)。

#3


0  

Change ASC to DESC.

改变ASC DESC。

That's "ascending" to "descending".

这是“上升”“下降”。

#4


0  

Use DESC in your ORDER BY statement:

在你的订单中使用DESC:

$result = mysql_query("SELECT * FROM Events ORDER BY ID DESC LIMIT 0, 10");

$result = mysql_query(“根据ID DESC LIMIT 0,10”从事件顺序中选择*);

#5


0  

change your ASC to DESC like this

把你的自动售货机换成这样的自动售货机

$result = mysql_query("SELECT * FROM Events ORDER BY ID DESC LIMIT 0, 10");

#6


0  

SELECT * FROM Events ORDER BY ID DESC LIMIT 0, 10

根据ID DESC限制0,10从事件顺序中选择*

#1


2  

You are sorting in ASCending order when you want to sort in DESCending order. Try the following instead:

当你想按降序排序时,你是按升序排序。试试以下:

$result = mysql_query("SELECT * FROM Events ORDER BY ID DESC LIMIT 0, 10");

If per chance, you want the 10 items with the lowest ID's but want them in descending order, then you could use the following:

如果您希望10个具有最低ID的项按降序排列,那么您可以使用以下方法:

$result = mysql_query("SELECT * FROM (SELECT * FROM Events ORDER BY ID ASC LIMIT 0, 10) ORDER BY ID DESC");

#2


2  

Pretty simple.

很简单。

ORDER BY ID DESC

(ASC means ascending, DESC means descending).

(ASC表示上升,DESC表示下降)。

#3


0  

Change ASC to DESC.

改变ASC DESC。

That's "ascending" to "descending".

这是“上升”“下降”。

#4


0  

Use DESC in your ORDER BY statement:

在你的订单中使用DESC:

$result = mysql_query("SELECT * FROM Events ORDER BY ID DESC LIMIT 0, 10");

$result = mysql_query(“根据ID DESC LIMIT 0,10”从事件顺序中选择*);

#5


0  

change your ASC to DESC like this

把你的自动售货机换成这样的自动售货机

$result = mysql_query("SELECT * FROM Events ORDER BY ID DESC LIMIT 0, 10");

#6


0  

SELECT * FROM Events ORDER BY ID DESC LIMIT 0, 10

根据ID DESC限制0,10从事件顺序中选择*