Page 2 of 2

Re: Data Retrieval and Table Display

Posted: Mon Nov 07, 2011 10:59 pm
by Gopesh
Hi,u want to display the data of the table. check this

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);

?>
Hope that it works for u...

Re: Data Retrieval and Table Display

Posted: Tue Nov 08, 2011 6:59 am
by Celauran
DarkSinister wrote:anyone tried out the files for the result themselves? =/
I just did. After about a billion undefined index notices, I get a list of numbers. The problem, therefore, isn't with the files but with the setup of your database or database server.