gpt4 book ai didi

php - mysqli php 选择最近的条目 asc

转载 作者:行者123 更新时间:2023-11-29 05:09:00 26 4
gpt4 key购买 nike

查询 DESC= 最近的。查询 asc = 最旧。我只是想获取最新条目以显示 ASC。使用 php assoc while 循环。

$sql = "SELECT id,userto,userfrom,message,dated FROM emailtable WHERE (userto='$email2 AND userfrom='$email1') OR (userto='$email1 AND userfrom='$email2') ORDER BY dated DESC LIMIT 10";

我应该如何获取最新条目以显示 ASC?

最佳答案

你也可以让 PHP 做一些工作,如果你只是在 SQL 中使用 DESC 选择最新的 10 个,你可以使用 array_reverse() 来按顺序显示结果.

$list = mysqli_fetch_all($result, MYSQLI_ASSOC);

foreach(array_reverse($list) as $row){
// oldest in list first.
}

或者,没有array_reverse():

for($i = count($list) - 1; $i >= 0; $i--){
print_r($list[$i]);
}

关于php - mysqli php 选择最近的条目 asc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42817674/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com