note 60271 added to ref.array
| From: | ryan1_00 at hotmail dot com | Date: | Sun, 01 Jan 2006 16:02:08 +0000 |
| Subject: | note 60271 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101076@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60271
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60271&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60271&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60271&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60271&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60271&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60271&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60271&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60271&report=yes
Search -- http://master.php.net/manage/user-notes.php