Page 1 of 1

How do I display all Records in a Table

Posted: Thu May 24, 2007 12:13 am
by reyes99
Hi Everyone,

Is there any easy way to display all records in a tables. I dont care about formating it. Just want them displayed preferably with the Field Names.

I am new to this and I dont understand arrays yet. So far everything I have found on displaying records I need to use an array. I have the following but I am getting the following error when I try to run it

"Parse error: parse error, unexpected '=' in.... On line 17"

Code: Select all

<?php
include 'config.php';
include 'opendb.php';

$query="SELECT * FROM table";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$field1-name=mysql_result($result,$i,"field1-name");
$field2-name=mysql_result($result,$i,"field2-name");
$field3-name=mysql_result($result,$i,"field3-name");
$field4-name=mysql_result($result,$i,"field4-name");
$field5-name=mysql_result($result,$i,"field5-name");

echo "<b>$field1-name 
$field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>";

$i++;
}	
?>


Thanks

Ralph

Posted: Thu May 24, 2007 12:26 am
by volka

Code: Select all

<?php
require 'config.php';
require 'opendb.php';

$query="SELECT * FROM table";
$result=mysql_query($query) or die(mysql_error());


echo '<table border="1"><tr>';
for($i=0; $i<mysql_num_fields($result); $i++) {
	echo '<th>', htmlentities(mysql_field_name($result, $i)), '</th>';
}
echo '</tr>';

while ( false!=($row=mysql_fetch_array($result, MYSQL_NUM)) ) {
	echo '<tr><td>', join('</td><td>', $row), '</td></tr>';
}
echo "</table>\n";
?>

Posted: Thu May 24, 2007 7:37 am
by reyes99
WOW Volka

That is exactly what I was looking for and Easy.


Thanks for the help


Ralph