note 55927 added to function.mysql-fetch-assoc

From: Date: Thu, 18 Aug 2005 01:06:43 +0000
Subject: note 55927 added to function.mysql-fetch-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-93816@lists.php.net to get a copy of this message
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> ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-assoc.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55927 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55927&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55927&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55927&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55927&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55927&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55927&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55927&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93816) next »