note 61170 added to function.mysql-field-name

From: Date: Fri, 27 Jan 2006 09:43:39 +0000
Subject: note 61170 added to function.mysql-field-name
Groups: php.notes 
Request: Send a blank email to php-notes+get-102534@lists.php.net to get a copy of this message
My need for simply printing lots of different (small) tables has led me to devise a way to automate this with a function. I was screwing around with the column headers when I stumbled upon the mysql_data_seek. I'm a noob, so please correct me. <?php function result2table($query) { global $connection; $result = mysql_query($query, $connection); $i = 0; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { switch($i) { case 0: //first line, column headers echo "<table border ='1'><tr>"; foreach ($row as $hash => $value) echo "<td><b>".$hash."</b></td>"; $i++; mysql_data_seek($result, 0); echo "</tr>"; break; default: //all others, draw data echo "<tr>"; foreach ($row as $value) echo "<td>" . $value . "</td>"; echo "</tr>"; $i++; } } echo "</table>"; } ?> ---- Server IP: 83.137.20.120 Probable Submitter: 212.238.182.206 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-field-name.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61170 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61170&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61170&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61170&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61170&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61170&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61170&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61170&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61170&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102534) next »