Re: Data Retrieval and Table Display
Posted: Mon Nov 07, 2011 10:59 pm
Hi,u want to display the data of the table. check this
Hope that it works for u...
Code: Select all
<?php
//step 1: connect & select DB
$db = "school_of_engineering";
$table = "inventory";
//$conn = @mysqli_connect("localhost","root","")or die("Unable to connect to $db");
$conn = mysqli_connect("localhost","root","") or die ("no mysql connection");
mysqli_select_db($conn,$db) or die ("test 01");
//Step 2: query the table
$sql = "select * from $table";
$query = mysqli_query($conn, $sql);
echo "<table border='1' cellspacing = '3' cellpadding= '3'>";
echo "<table heading='1'";
//step3: retreive and display the data
$row = mysqli_fetch_row($query);
do{
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "</tr>";
$row = mysqli_fetch_row($query);
}while($row);
echo "</table>";
//step 4: free the memory
mysqli_free_result($query);
//step 5: close the connection
mysqli_close($conn);
?>