非常教程

PHP参考手册

PHP MySQL Order By 关键词

PHP MySQL Order By 关键词

PHP MySQL Order By 关键词


ORDER BY 关键词用于对记录集中的数据进行排序。


ORDER BY 关键词

ORDER BY 关键词用于对记录集中的数据进行排序。

ORDER BY 关键词默认对记录进行升序排序。

如果你想降序排序,请使用 DESC 关键字。

语法

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC

如需学习更多关于 SQL 的知识,请访问我们的 SQL 教程。

实例

下面的实例选取 "Persons" 表中存储的所有数据,并根据 "Age" 列对结果进行排序:

<?php
$con=mysqli_connect("localhost","username","password","database");
// 检测连接
if (mysqli_connect_errno())
{
    echo "连接失败: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Persons ORDER BY age");

while($row = mysqli_fetch_array($result))
{
    echo $row['FirstName'];
    echo " " . $row['LastName'];
    echo " " . $row['Age'];
    echo "<br>";
}

mysqli_close($con);
?>

以上结果将输出:

Glenn Quagmire 33
Peter Griffin 35


根据两列进行排序

可以根据多个列进行排序。当按照多个列进行排序时,只有第一列的值相同时才使用第二列:

SELECT column_name(s)
FROM table_name
ORDER BY column1, column2
PHP MySQL Order By 关键词

PHP目录

1.PHP Error 和 Logging 函数
2.PHP 5 Directory 函数
3.PHP 5 Date/Time 函数
4.PHP 5 Calendar 函数
5.PHP 5 Array 函数
6.PHP 5 SimpleXML 函数
7.PHP 5 MySQLi 函数
8.PHP Misc. 函数
9.PHP 5 Math 函数
10.PHP Mail 函数
11.PHP Libxml 函数
12.PHP HTTP 函数
13.PHP FTP 函数
14.PHP Filter 函数
15.PHP 5 Filesystem 函数
16.PHP 简介
17.PHP 教程
18.PHP Zip File 函数
19.PHP XML 函数
20.PHP 5 String 函数
21.PHP 语法
22.PHP 安装
23.PHP If…Else 语句
24.PHP 运算符
25.PHP 字符串变量
26.PHP 变量
27.PHP 函数
28.PHP For 循环
29.PHP While 循环
30.PHP 数组排序
31.PHP 数组
32.PHP Switch 语句
33.PHP include 和 require
34.PHP date() 函数
35.PHP 安全 E-mail
36.PHP 邮件
37.PHP Session
38.PHP Cookie
39.PHP 文件
40.PHP 异常处理
41.PHP 错误处理
42.PHP MySQL 读取数据
43.PHP MySQL 插入数据
44.PHP MySQL 创建数据库
45.PHP MySQL 简介
46.PHP – AJAX 与 PHP
47.PHP XML SimpleXML
48.PHP XML DOM
49.PHP XML Expat 解析器
50.PHP 数据库 ODBC
51.PHP MySQL Delete
52.PHP MySQL Update
53.PHP MySQL Order By 关键词
54.PHP MySQL Where 子句
55.PHP 实例 AJAX 投票
56.PHP 实例 AJAX RSS 阅读器
57.PHP 实例 AJAX 实时搜索
58.PHP 实例 AJAX 与 XML
59.PHP 实例 AJAX 与 MySQL
60.PHP array() 函数
61.PHP 5 Timezones
62.PHP array_fill() 函数
63.PHP array_diff_ukey() 函数
64.PHP array_diff_uassoc() 函数
65.PHP array_diff_key() 函数
66.PHP array_diff_assoc() 函数
67.PHP array_diff() 函数
68.PHP array_count_values() 函数
69.PHP array_combine() 函数
70.PHP array_chunk() 函数
71.PHP array_change_key_case() 函数
72.PHP array_key_exists() 函数
73.PHP array_intersect_ukey() 函数
74.PHP array_intersect_uassoc() 函数
75.PHP array_intersect_key() 函数
76.PHP array_intersect_assoc() 函数
77.PHP array_intersect() 函数
78.PHP array_flip() 函数
79.PHP array_filter() 函数
80.PHP array_fill_keys() 函数
81.PHP array_map() 函数
82.PHP array_keys() 函数
83.PHP array_reduce() 函数
84.PHP array_rand() 函数
85.PHP array_push() 函数
86.PHP array_product() 函数
87.PHP array_pop() 函数
88.PHP array_pad() 函数
89.PHP array_multisort() 函数
90.PHP array_merge_recursive() 函数
91.PHP array_merge() 函数
92.PHP array_uintersect() 函数
93.PHP array_udiff_uassoc() 函数
94.PHP array_udiff_assoc() 函数
95.PHP array_udiff() 函数
96.PHP array_sum() 函数
97.PHP array_splice() 函数
98.PHP array_slice() 函数
99.PHP array_shift() 函数
100.PHP array_search() 函数