[PHP-DB] Awkward query - simpler method? From: Daniel Barton (dbarton <email protected>)
Date: 11/30/01

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 <email protected>
dbarton <email protected>

-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe <email protected> For additional commands, e-mail: php-db-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>