复制代码 代码如下:
SELECT column_name(s)
FROM table_name
ORDER BY column_name
复制代码 代码如下:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM person ORDER BY age");
while($row = mysql_fetch_array($result))
{
echo $row['FirstName']
echo " " . $row['LastName'];
echo " " . $row['Age'];
echo "<br />";
}
mysql_close($con);
?>
[html]
上面的代码将输出下面的结果:
Glenn Quagmire 33
Peter Griffin 35
按照升序或者降序进行分类排列
如果你使用了“ORDER BY”关键词,所有记录将按照默认的升序进行排列(即:从1到9,从a到z)
使用“DESC”关键词可以制定所有的数据按照降序排列(即:从9到1,从z到a):
[code]
SELECT column_name(s)
FROM table_name
ORDER BY column_name DESC
复制代码 代码如下:
SELECT column_name(s)
FROM table_name
ORDER BY column_name1, column_name2
新闻热点
疑难解答