Created
August 4, 2012 20:32
-
-
Save nomanson/3259771 to your computer and use it in GitHub Desktop.
Revisions
-
nomanson created this gist
Aug 4, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ function make_table($sql) { $res = mysql_query("$sql"); if (!$res) { die("Query to show fields from table failed"); } $rows_num = mysql_num_rows($res); if (!$rows_num) { echo "<p>No information avaliable!</p>"; } else { $fields_num = mysql_num_fields($res); echo "<table><tr>"; // printing table headers for ($i = 0; $i < $fields_num; $i++) { $field = mysql_fetch_field($res); echo "<th>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while ($row = mysql_fetch_row($res)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach ($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } echo "</table>"; } }