当我使用SELECT * FROM样本时,我怎样才能把它放在TOP上

时间:2014-10-30 01:37:42

标签: php

例如

$query = mysql_query("SELECT * FROM sample");

while ($row = mysql_fetch_array($query)){

echo 'Hello, '.$row['name'].'.<br>';
}

Hello, sample.
Hello, sample1.
Hello, sample2.

我希望sample2转到TOP。 ^

Hello, sample2.
Hello, sample1.
Hello, sample.

2 个答案:

答案 0 :(得分:1)

$query = "SELECT * FROM sample ORDER BY [field name] ASC/DESC (ascending/descending)";

希望这有帮助。

答案 1 :(得分:1)

你可以使用order by子句..这是语法

SELECT * FROM sample order by name desc