Thursday, August 22, 2013

How to Fetching Data From Database

Create a file Fetch with the coding:


<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("table", $con);

$result = mysql_query("SELECT * FROM student");

echo "<table border='1'>
<tr>
<th>name</th>
<th>class</th>
<th>rollno</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['class'] . "</td>";
  echo "<td>" . $row['rollno'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>
</body>
</html>


No comments: