note 81348 deleted from function.mysql-query by philip
| From: | philip@php.net | Date: | Fri, 04 Sep 2015 19:19:08 +0000 |
| Subject: | note 81348 deleted from function.mysql-query by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203642@lists.php.net to get a copy of this message | ||
Note Submitter: kriskra at gmail dot com
----
Here is a small neat function to print out the mysql result as a html table:
<?php
function echo_result($result) {
?><table><tr><?
if(! $result) { ?><th>result not valid</th><? }
else {
$i = 0;
while ($i < mysql_num_fields($result)) {
$meta = mysql_fetch_field($result, $i);
?><th style="white-space:nowrap"><?=$meta->name?></th><?
$i++;
}
?></tr><?
if(mysql_num_rows($result) == 0) {
?><tr><td colspan="<?=mysql_num_fields($result)?>">
<strong><center>no result</center></strong>
</td></tr><?
} else
while($row=mysql_fetch_assoc($result)) {
?><tr style="white-space:nowrap"><?
foreach($row as $key=>$value) { ?><td><?=$value?></td><? }
?></tr><?
}
}
?></table><?
}
?>