note 55927 deleted from function.mysql-fetch-assoc by victor

From: Date: Thu, 18 Aug 2005 06:51:08 +0000
Subject: note 55927 deleted from function.mysql-fetch-assoc by victor
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93823@lists.php.net to get a copy of this message
Note Submitter: cristian dot ditoiu at webmaker dot ro ---- To print out the information from a databse without knowing in advance the names of the fields or how many fields you'll get : <table> <? include 'connection_to_the_database.inc'; $q='select id as numar , clicks,title as title,rand() as random from content order by id desc limit 0,10'; $result = mysql_query($q,$connection); while($row = mysql_fetch_assoc($result)) { $array_out[]=$row; } $keys=(array_keys($array_out[0])); reset($array_out); while (list(,$field) = each($keys)) { echo "<th>$field</th>\n"; } echo "\n"; reset($keys); while (list($result_id)=each($array_out)) { echo "<tr>\n"; while (list(,$field) = each($keys)) { $value=$array_out[$result_id][$field]; echo "\t<td>$value</td>\n"; } reset($keys); if($result_id+1%count($keys)) { echo "</tr>\n"; } } ?> </table>

« previous php.notes (#93823) next »