Awkward query - simpler method?
| From: | Daniel Barton | Date: | Fri, 30 Nov 2001 18:18:32 +0000 |
| Subject: | Awkward query - simpler method? | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-14726@lists.php.net to get a copy of this message | ||
Hi,
I can't seem to nail down the simplest way to do this. I've got
10-15 lines of code right now to do something that should take less. The
following code extracts the names of all the fields in a table, prints
them across a table row in their own cells, and then extracts each
record and prints a table row for each.
$result = mysql_query("SELECT * FROM meatmap");
echo "<table>\r\n";
echo "<tr>\r\n";
$row = mysql_fetch_assoc($result);
foreach($row as $key => $value) {echo "<td>$key</td>\r\n"; }
echo "</tr>\r\n";
mysql_data_seek($result, 0);
while($row = mysql_fetch_assoc($result)) {
echo "<tr>";
foreach($row as $key => $value) {echo "<td>$value</td>\r\n"; }
echo "</tr>";
}
echo "</table>\r\n";
I know there has to be an easier way, both concept and code wise, to
do this. Any ideas out there? A message earlier this week gave me the
general idea... the previous way I had been doing this was EVEN MORE
ungainly.
Thanks,
db
--
----------
Dan Barton
Terrestrial Program Biologist
Asst. Data Manager
Point Reyes Bird Observatory
http://www.prbo.org
dbarton@prbo.org
dbarton@grayflycatcher.org