note 61170 deleted from function.mysql-field-name by mazzanet
| From: | mazzanet@php.net | Date: | Fri, 27 Jan 2006 10:26:31 +0000 |
| Subject: | note 61170 deleted from function.mysql-field-name by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-102549@lists.php.net to get a copy of this message | ||
Note Submitter: Sander
----
My need for simply printing lots of different (small) tables has led me to devise a way to automate
this with a function. I was screwing around with the column headers when I stumbled upon the
mysql_data_seek. I'm a noob, so please correct me.
<?php
function result2table($query)
{
global $connection;
$result = mysql_query($query, $connection);
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
switch($i)
{
case 0: //first line, column headers
echo "<table border ='1'><tr>";
foreach ($row as $hash => $value)
echo "<td><b>".$hash."</b></td>";
$i++;
mysql_data_seek($result, 0);
echo "</tr>";
break;
default: //all others, draw data
echo "<tr>";
foreach ($row as $value)
echo "<td>" . $value . "</td>";
echo "</tr>";
$i++;
}
}
echo "</table>";
}
?>