PHP MySQL Order By – An Example

In PHP ORDER BY keyword is used for sort data in different methods. For example we can sort the recordset in ascending order, descending order etc. By default ORDER BY keyword sorts the records in ascending order. If you want to order the data then you can use the keyword DESC with query.


SELECT * FROM table_name ORDER BY column_name(s) DESC

PHP MySQL Order By Example

$result = mysql_query("SELECT * FROM Students ORDER BY Age");
 while($row = mysql_fetch_array($result)){
	   echo $row['Name'];
	   echo " " . $row['Class'];
	   echo " " . $row['Age'];
	   echo "<br />";

The output of the above code will be:

John 8th.std 12
Roy 10th.std 15
Tags: ,

Related posts:

HTML5 page structure

HTML5 offers more powerful structure comparing to older versions of Html. There are many new …

Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us