note 89048 added to mysql.examples-basic
| From: | Sz dot abi at osu1 dot php dot net | Date: | Thu, 19 Feb 2009 11:26:26 +0000 |
| Subject: | note 89048 added to mysql.examples-basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150848@lists.php.net to get a copy of this message | ||
You might want to do something like this to output the column names as well:
<?php
echo "<table border=\"1\">\n";
$line = mysql_fetch_array($result, MYSQL_ASSOC);
echo "\t<tr>\n";
echo "\t\t<th>#</th>\n";
foreach (array_keys($line) as $col_value) {
echo "\t\t<th>$col_value</th>\n";
}
echo "\t</tr>\n";
$i=0;
do {
echo "\t<tr>\n";
$i++;
echo "\t\t<th>$i</th>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}while ($line = mysql_fetch_array($result, MYSQL_ASSOC));
echo "</table>\n";
?>
(Ok, here I also added line numbers; the main point of this post is using array_keys(...) to display
the column names, and using a do {...} while (...); construct to read the first line only once).
----
Server IP: 81.223.48.75
Probable Submitter: 77.117.181.91
----
Manual Page -- http://www.php.net/manual/en/mysql.examples-basic.php
Edit -- https://master.php.net/note/edit/89048
Del: integrated -- https://master.php.net/note/delete/89048/integrated
Del: useless -- https://master.php.net/note/delete/89048/useless
Del: bad code -- https://master.php.net/note/delete/89048/bad+code
Del: spam -- https://master.php.net/note/delete/89048/spam
Del: non-english -- https://master.php.net/note/delete/89048/non-english
Del: in docs -- https://master.php.net/note/delete/89048/in+docs
Del: other reasons-- https://master.php.net/note/delete/89048
Reject -- https://master.php.net/note/reject/89048
Search -- https://master.php.net/manage/user-notes.php