note 89048 deleted from mysql.examples-basic by googleguy

From: Date: Sat, 12 Jan 2013 09:44:31 +0000
Subject: note 89048 deleted from mysql.examples-basic by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192962@lists.php.net to get a copy of this message
Note Submitter: Sz.abi ---- 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).

« previous php.notes (#192962) next »