开发者

How do I only descend this part for my loop?

Okay guys! Right now, I am using Descending for my data because i want the dates from newest to oldest, but I want the entries from that data to be oldest to newest. So how can I do this, especially since I am using DESC in my query. Basically descend the <li> portions

        $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>";

Output:

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


You can order your SQL query by multiple criteria simultaneously. Try changing your ORDER BY clause from this:

ORDER BY DATEandTIME DESC

to this:

ORDER BY `Date` DESC, TIME(DATEandTIME) ASC
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜