connection.inc.php :
<?php
$host='localhost';
$user_name='root';
$password='';
@$con = mysql_connect("$host","$user_name","$password");
if ($con)
{echo '<br>host coonected<br>';}
else
{
die('Could not connect ');
}
?>
order_by_table.php :
<?php
require 'connection.inc.php';
if (mysql_select_db('test'))
if($result=mysql_query("select * from test order by name",$con))
{
echo "<br><table><tr><td>sno</td><td>name</td></tr>";
while($data = mysql_fetch_array($result))
{
echo "<tr><td>".$data['sno'] . "</td><td>" .$data['name']."</td></tr>";
}
echo "</table><br>data selected<br>";
}
else
{
echo '<br>data not selected :'.mysql_error().'<br>';
}
mysql_close($con);
?>
run " order_by_table.php "
output :
host coonected
data selected
<?php
$host='localhost';
$user_name='root';
$password='';
@$con = mysql_connect("$host","$user_name","$password");
if ($con)
{echo '<br>host coonected<br>';}
else
{
die('Could not connect ');
}
?>
order_by_table.php :
<?php
require 'connection.inc.php';
if (mysql_select_db('test'))
if($result=mysql_query("select * from test order by name",$con))
{
echo "<br><table><tr><td>sno</td><td>name</td></tr>";
while($data = mysql_fetch_array($result))
{
echo "<tr><td>".$data['sno'] . "</td><td>" .$data['name']."</td></tr>";
}
echo "</table><br>data selected<br>";
}
else
{
echo '<br>data not selected :'.mysql_error().'<br>';
}
mysql_close($con);
?>
run " order_by_table.php "
output :
host coonected
sno | name |
2 | human |
2 | human |
data selected