This example illustrates how to execute query with ORDER BY clause in the php application.
ORDER BY clause is used to sort the result data either in the ascending order or descending order. By default, the it is taken in ascending order. ASC keyword can be used explicitly for ascending order. To make the order in descending order, "DESC" keyword is used. ORDER BY clause is used in conjunction with the name of the column based on which the sorting is performed.
In this example, we have created a sqlorderby.php file in which
we executed a query to fetch the employee list in descending order. First,
connection from database is created using mysql_connect("hostName",
"userName", "Password"), selected the database by
mysql_select_db("databaseName", connectionObject). Now, the query
SELECT * FROM emp ORDER BY name DESC"
is executed to get the desired result. This query returns the the rows in the
descending order of name.
Source Code of sqlorderby.php
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: January 20, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles