gpt4 book ai didi

php - 如何按变量排序?

转载 作者:行者123 更新时间:2023-11-29 13:38:39 25 4
gpt4 key购买 nike

我不知道为什么它不起作用...我正在尝试“排序”创建的变量,如下所示:

mysql_query("SELECT *,DATE_FORMAT(FROM_UNIXTIME(banfrom), '%d/%m/%Y') as time FROM ab_list WHERE time = '24/08/2013' ORDER BY banfrom DESC LIMIT 0,50");

或者,

   $hr = date('d/m/Y');
mysql_query("SELECT *,DATE_FORMAT(FROM_UNIXTIME(banfrom), '%d/%m/%Y') as time FROM ab_list WHERE time = '$hr' ORDER BY banfrom DESC LIMIT 0,50");

最佳答案

假设变量$hr的格式为%d/%m/%Y,您可以使用having代替 >where 过滤记录。

mysql_query("SELECT *,DATE_FORMAT(FROM_UNIXTIME(banfrom), '%d/%m/%Y') as time 
FROM ab_list
HAVING time = '$hr'
ORDER BY banfrom DESC
LIMIT 0,50");

在这种情况下使用 HAVING 而不是 WHERE 的原因是因为 time 是计算列。

关于php - 如何按变量排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18420086/

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