Computer Applications

Saturday, January 23, 2010

The ORDER BY Keyword in MySQL

It is is used to sort the data in a record-set.

Code:

$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'];
}
mysql_close($con);
?>

No comments:

Post a Comment