好的伙计们!现在,我使用Descending作为我的数据,因为我想要从最新到最旧的日期,但我希望从该数据的条目最旧到最新。那我怎么能这样做,特别是因为我在查询中使用DESC。基本上下降<li>
部分
$sql = "SELECT $column_name, DATE(DATEandTIME) as Date FROM Codes WHERE DATEandTIME >= DATE_SUB(CURDATE(), INTERVAL 3 DAY) ORDER BY DATEandTIME DESC";
$results = mysql_query($sql) or die(mysql_error());
$prev_date = null;
while ( $row = mysql_fetch_array($results) ) {
if( $row['Date'] != $prev_date ) {
echo "</ol>";
echo $row['Date'];
echo "<ol>";
$prev_date = $row['Date'];
}
echo "<li>" . $row[$column_name] . "</li> " . $row['DATEandTIME'];
}
echo "</ol>";
输出:
2009-11-13
1. Green
2009-11-13 17:09:
2. 35TQTTX
2009-11-13 16:27:
3. 422AMKF
2009-11-13 14:42:
4. 35gqedu
2009-11-13 14:03:
5. 15T9YT6
2009-11-13 13:42:
6. 41TBK99
2009-11-13 13:38:47
答案 0 :(得分:3)
您可以同时按多个条件排序SQL查询。尝试更改此ORDER BY
子句:
ORDER BY DATEandTIME DESC
到此:
ORDER BY `Date` DESC, TIME(DATEandTIME) ASC