Home Php php MySQL order by clause



php MySQL order by clause
Posted on: December 17, 2009 at 12:00 AM
In SQL generally we use three clauses, select ,from, and where.

php MySQL order by clause:

     

In SQL generally we use three clauses, select ,from, and where.  There are many more clauses are present in SQL which are used for different purpose. Order by is one of the important clause of SQL. Order by clause is used to sort a particular field in either ascending order or descending order.

General Format of SQL is as follows:

select <list of fields to be displayed or * for displaying all fields>

from <table name>

where <condition if any>

order by <field name> <asc-for ascending order, it is default order or desc-for descending order>

Example:

<?php

$db=@mysql_connect("localhost","root","");

if(!$db)

{

die("Can not establish connection".mysql_error());

}

mysql_select_db("roseindia",$db);

$result=mysql_query("select * from student order by name asc");

while($row=mysql_fetch_array($result))

{

echo $row['age'];

echo" ".$row['name'];

echo"<br/>";

}

?>

Output:

28 rahul
28 shantanu
27 vikash
26 vinay

Related Tags for php MySQL order by clause:


More Tutorials from this section

Ask Questions?    Discuss: php MySQL order by clause  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.