Keyword of the order by command of MySQL in PHP
Is used to sort data records.
Keyword of this command
Is used to sort data records.
By default, records sorted by command keywords are sorted in ascending order.
If you want to sort records in a descending order, you can use the description of the keyword.
Syntax
SELECT column_name(s)FROM table_nameORDER BY column_name(s) ASC|DESC
For more information about SQL, see our SQL tutorial.
For example
In the following example, all data is stored in the "person" table, and various "Age" columns are displayed:
$ 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 Persons order by age "); while ($ row = mysql_fetch_array ($ result) {echo $ row ['firstname']; echo "". $ row ['lastname']; echo "". $ row ['age']; echo "<br/> ";}
mysql_close($con);
Output.
Glenn Quagmire 33Peter Griffin 35
Command Columns
It is also possible to exceed one column. When you order more than one column, the second column only uses value, if the first column is equal:
SELECT column_name(s)FROM table_nameORDER BY column1, column2
For more information, see www.111cn.cn/database/database.html.