PHP – Display All Rows and Fields of a Table

The given PHP example helps you to display all the rows and the fields of a table. 

Code Example:
<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "school";

$conn	=  mysql_connect($server, $username, $password) or die("Couldn't connect to MySQL" . mysql_error());
mysql_select_db($database, $conn) or die ("Couldn't open $test: " . mysql_error());
$result = mysql_query("SELECT * FROM student");
$records = mysql_num_rows($result);

echo "$records records have been added into the table.";

echo "<table>";
while ($row = mysql_fetch_row($result)){
  echo "<tr>";
  foreach ($row as $field){
    echo "<td>".stripslashes($field)."</td>";
  }
  echo "</tr>";
}
echo "</table>";
mysql_close($conn);
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *