Dynamic Tables

From: Date: Mon, 07 Jun 2004 15:33:17 +0000
Subject: Dynamic Tables
Groups: php.general 
Request: Send a blank email to php-general+get-187795@lists.php.net to get a copy of this message
What is the best way to produce a report listing the fieldname and then the data in that field. It is a report containing only one row from a table, but I don't want to hard code the fields since they change often. I can get the field names dynamically like this: $fields = mysql_list_fields("Network", "Subnets"); $num_columns = mysql_num_fields($fields); for($ i = 0; $i < $num_columns; $i++) { echo mysql_field_name($fields, $i); } now is where I get confused....what I would like to happen is do a query on a single row and put the results into mysql_fetch_assoc and during the prior loop put the column name into the loop of the data. Something like: $fields = mysql_list_fields("Network", "Subnets"); $num_columns = mysql_num_fields($fields); $result = mysql_query("SELECT * FROM table1 WHERE ID = '$ID'; $field = mysql_fetch_assoc($result) for($ i = 0; $i < $num_columns; $i++) { echo "<b>" . mysql_field_name($fields, $i) . ": </b>" . $field[mysql_field_name($fields, $i)] . "<br>\n";

« previous php.general (#187795) next »