note 32779 added to ref.mysql

From: Date: Fri, 06 Jun 2003 17:26:02 +0000
Subject: note 32779 added to ref.mysql
Groups: php.notes 
Request: Send a blank email to php-notes+get-49894@lists.php.net to get a copy of this message
I wrote this function to replace mysql's <em>mysql --html</em> function. It takes the result of a query, and creates the table. Usage is as follows: $result = mysql_query("SELECT col1,col2 FROM yourtable LIMIT 100") sqlDoTable($result) function sqlDoTable ($result) { print "<table border=1 cellpadding=3 cellspacing=0>"; // Print Table Title print "<tr>"; for ($i=0;$i < mysql_num_fields($result);$i++) { print "<th>" . mysql_field_name($result, $i) . "</th>"; } print "</tr>\n"; // Print table Content for ($i=0;$i < mysql_num_rows($result);$i++) { print "<tr>"; $row = mysql_fetch_row($result); foreach ($row as $value) { // Make sure 0's are displayed if (is_numeric($value)) { $value = (int)$value; } // Make sure table is displayed correctly if (empty($value) && ($value !== 0)) { $value = "&nbsp;"; } else { $value = htmlspecialchars($value); } print "<td>$value</td>"; } print "</tr>\n"; } print "</table>"; } ---- Manual Page -- http://www.php.net/manual/en/ref.mysql.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32779 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32779&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32779&report=yes

« previous php.notes (#49894) next »