note 32779 deleted from ref.mysql by aidan
| From: | aidan@php.net | Date: | Sun, 15 Aug 2004 11:09:53 +0000 |
| Subject: | note 32779 deleted from ref.mysql by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74692@lists.php.net to get a copy of this message | ||
Note Submitter: imho at auspantheon dot com
----
I wrote this function to replace mysql's <em>mysql --html</em> function.
It takes the result of a query, and creates the table.
Usage is as follows:
$result = mysql_query("SELECT col1,col2 FROM yourtable LIMIT 100")
sqlDoTable($result)
function sqlDoTable ($result) {
print "<table border=1 cellpadding=3 cellspacing=0>";
// Print Table Title
print "<tr>";
for ($i=0;$i < mysql_num_fields($result);$i++) {
print "<th>" . mysql_field_name($result, $i) . "</th>";
}
print "</tr>\n";
// Print table Content
for ($i=0;$i < mysql_num_rows($result);$i++) {
print "<tr>";
$row = mysql_fetch_row($result);
foreach ($row as $value) {
// Make sure 0's are displayed
if (is_numeric($value)) { $value = (int)$value; }
// Make sure table is displayed correctly
if (empty($value) && ($value !== 0)) { $value = " "; } else { $value =
htmlspecialchars($value); }
print "<td>$value</td>";
}
print "</tr>\n";
}
print "</table>";
}