note 25664 added to function.mysql-num-fields

From: Date: Tue, 01 Oct 2002 20:52:49 +0000
Subject: note 25664 added to function.mysql-num-fields
Groups: php.notes 
Request: Send a blank email to php-notes+get-37485@lists.php.net to get a copy of this message
Adding to the last comment: you can dynamically loop through any number of columns AND rows like so- $query="your SQL"; $result=mysql_query($query) or die("Query ($query) sucks!"); $fields=mysql_num_fields($result); echo "<table>\n<tr>"; for ($i=0; $i < mysql_num_fields($result); $i++) //Table Header { print "<th>".mysql_field_name($result, $i)."</th>"; } echo "</tr>\n"; while ($row = mysql_fetch_row($result)) { //Table body echo "<tr>"; for ($f=0; $f < $fields; $f++) { echo "<td>$row[$f]</td>"; } echo "</tr>\n";} echo "</table><p>"; This has been tested. -- http://www.php.net/manual/en/function.mysql-num-fields.php http://master.php.net/manage/user-notes.php?action=edit+25664 http://master.php.net/manage/user-notes.php?action=delete+25664 http://master.php.net/manage/user-notes.php?action=reject+25664

« previous php.notes (#37485) next »