Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Order By

We use Order By Keyword to sort the records in a recordset. The general syntax is as under.

Syntax:

SELECT columnname(s) FROM tablename ORDER BY columnname SortOrder

 

Example:
Table Name(empinfo)
FirstName
LastName
Email
DOB
Steve
Martin
smart.steve@studiesinn.com
08-04-1988
David
Fernandas
davidfernandas@studiesinn.com
04-16-1977
Ajay
Rathor
ajayrathor@studiesinn.com
08-24-1986

 

$con = mysql_connect("localhost:3306","adam","123456");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("mydb", $con);
$result = mysql_query("SELECT * FROM empinfo order by FirstName asc");
while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'] . “ “ $row[‘DOB];
  echo "
";
  }
mysql_close($con);
?>

 

The Output will be
Ajay Rathor 08-24-1986
David Fernandas 04-16-1977
Steve Martin 08-04-1988
Note:

SortOrder is optional if you does not use it the records will be sorted in ascending order (1 to 10 or a to z).  Use DESC as SortOrder to sort records in descending order. RAND() is used for random sort. SQL statements are not case sensitive. You can use both capital letters and small letter.

 

 
     
   
PHP Tutorial
 
  Introduction
Introduction
  Variables
Variables
  Strings
Strings
  Operators
Operators
  If Else Statement
If Else Statement
  Loops
Loops
  Functions
Functions
  Forms
Forms
  Sessions
Sessions
  Cookies
Cookies
  Files
Files
  E-mail
E-mail
  Error Handling
Error Handling
  File Upload
File Upload
  PHP Databases
PHP Databases
  Connecting to a MySQL Database
Connecting to a MySQL Database
  MySQL Data Types
MySQL Data Types
  Inserting Data Into a Table
Inserting Data Into a Table
  Select Statement
Select Statement
  Where Clause
Where Clause
  Order By
Order By
  Update Statement
Update Statement
  Delete From Statement
Delete From Statement
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download The 7 Great Lies Of Network Marketing Ebook The 7 Great Lies Of Network Marketing
   
Download What Is Web 2 0  Free Link Baiting Strategies Ebook What Is Web 2 0 Free Link Baiting Strategies
   
Download How to use targeted social networks to reach people of influence and get viral e Ebook How to use targeted social networks to reach people of influence and get viral e
   
Download 30 Days To Create A Product Ebook 30 Days To Create A Product
   
Download Concrete Abstractions - An Introduction to Computer Science Using Scheme  Ebook Concrete Abstractions - An Introduction to Computer Science Using Scheme
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz