note 65286 deleted from ref.mysql by bjori
| From: | bjori@php.net | Date: | Fri, 28 Apr 2006 13:14:41 +0000 |
| Subject: | note 65286 deleted from ref.mysql by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109975@lists.php.net to get a copy of this message | ||
Note Submitter: philip dot clarke at midkent dot ac dot uk
Reason: useless
----
I was experimenting with functions and thought I would try my hand at a general purpose 'print
the contents of an array generated by a query'. This does not require the names of the
attributes and therefore only displays them as they are in the array. The function only generates
the repeating data lines and needs the appropriate html table construction. I have included an
example at the end of my note and as you can see I have added a top header row, you would need to
change this to suit your query.
function print_query_table ($query_result) //By Philip Clarke 27/04/2006
{
while ($data = mysql_fetch_row($query_result))
{
$i = 0;
echo "<tr>";
while ($data[$i++])
{
echo "<td>$data[$i]</td>";
}
echo "</tr>";
}
}
Example Usage:
<table width="30%" border="4">
<tr>
<th>ITEM ID</th>
<th>ITEM TITLE</th>
<th>ITEM DESCRIPTION</th>
<th>ITEM PRICE </th>
</tr><?php print_query_table ($result); ?>
</table>