Search This Blog

order by in php with mysql

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

snoname
2human
2human

data selected


Share Links

Related Posts Plugin for WordPress, Blogger...