note 65286 added to ref.mysql
| From: | philip dot clarke at midkent dot ac dot uk | Date: | Fri, 28 Apr 2006 08:42:10 +0000 |
| Subject: | note 65286 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-109935@lists.php.net to get a copy of this message | ||
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>
----
Server IP: 85.116.0.130
Probable Submitter: 129.12.189.75
----
X-Spam-Status: Yes, hits=5.4 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_30_40,HTML_MESSAGE,HTML_TABLE_THICK_BORD,UPPERCASE_25_50
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/ref.mysql.php
Edit -- http://master.php.net/note/edit/65286
Del: integrated -- http://master.php.net/note/delete/65286/integrated
Del: useless -- http://master.php.net/note/delete/65286/useless
Del: bad code -- http://master.php.net/note/delete/65286/bad+code
Del: spam -- http://master.php.net/note/delete/65286/spam
Del: non-english -- http://master.php.net/note/delete/65286/non-english
Del: in docs -- http://master.php.net/note/delete/65286/in+docs
Del: other reasons-- http://master.php.net/note/delete/65286
Reject -- http://master.php.net/note/reject/65286
Search -- http://master.php.net/manage/user-notes.php