note 60271 deleted from ref.array by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 19:23:06 +0000 |
| Subject: | note 60271 deleted from ref.array by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134500@lists.php.net to get a copy of this message | ||
Note Submitter: ryan1_00 at hotmail dot com
----
The following will take a query result and create a dynamic table for it. Using the Key() function
to get the table headers and the current() function for the actual values.
$result = mysql_query($qry) or die ("<center> ERROR:
".mysql_error()."</center>");
$x = 0;
echo "<table border=\"1\" align=\"center\">";
while($row = mysql_fetch_assoc($result))
{
if ($x == 0) // so that table headers are only created on the first pass
{
$col = (count($row)); // counts number of elements in the array
$x=1;
echo "<tr>";
for ($y=0; $y<$col; $y++)
{
echo "<th>";
echo key($row); // gets the names of the fields
echo "</th>";
next($row);
}
echo "</tr>";
}
reset($row);
echo "<tr>";
for ($y=0; $y<$col; $y++)
{
echo "<td valign=\"top\" align=\"left\">";
echo current($row);
echo"</td>";
next($row);
}
echo "</tr>";
} // end of while loop