Skip to content

Instantly share code, notes, and snippets.

@Artur-
Last active August 29, 2015 14:21
Show Gist options
  • Save Artur-/4ac29ad04358b78673c0 to your computer and use it in GitHub Desktop.
Save Artur-/4ac29ad04358b78673c0 to your computer and use it in GitHub Desktop.
<?php
function mysqlGrid($table, $columns="") {
if ($columns=="") {
$columns = array();
$q = "DESC $table";
$r = mysql_query($q);
while ($row = mysql_fetch_row($r)) {
$columns[] = $row[0];
}
}
echo "<table>";
// Columns
echo "<colgroup>";
for ($i=0 ; $i < count($columns); $i++) {
$col = $columns[$i];
echo "<col header-text=\"$col\">\n";
}
echo "</colgroup>";
// Data
echo "<tbody>";
$r = mysql_query("SELECT * FROM $table");
while ($row = mysql_fetch_assoc($r)) {
echo "<tr>";
foreach ($columns as $col) {
echo "<td>";
echo $row[$col];
echo "</td>";
}
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment