如何以不同的顺序显示记录

时间:2010-12-16 01:23:04

标签: php sql mysql

我从这个小的PHP和mysql脚本开始。我如何通过 taskupdated列来显示任务?

$query = "SELECT * FROM tasks2 where owner=72";

$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) {
    echo $row['ownername'];
    echo ' - ';
    echo $row['tasktitle'];
    echo '<br/>';
    echo $row['taskdetails'];
    echo '<hr/>';
}

2 个答案:

答案 0 :(得分:4)

<?php

$query = "SELECT * FROM tasks2 WHERE owner=72 ORDER BY taskupdated";

$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result)) {
    echo $row['ownername'];
    echo ' - ';
    echo $row['tasktitle'];
    echo '<br />';
    echo $row['taskdetails'];
    echo '<hr />';
}

?>

如果您想以其他方式对其进行排序,请改用ORDER BY taskupdated DESC

答案 1 :(得分:3)

SELECT * FROM tasks2 where owner=72 ORDER BY taskupdated