Skip to content

Instantly share code, notes, and snippets.

@shameen
Created August 3, 2011 15:07
Show Gist options
  • Save shameen/1122853 to your computer and use it in GitHub Desktop.
Save shameen/1122853 to your computer and use it in GitHub Desktop.
Function to print out the contents of a MySQL table, formatted as an HTML table with classes
<?php
/*shameen.info*/
function shameen_print_table($tablename) {
$data = mysql_query('SELECT * FROM accounts');
$cols = mysql_query('SHOW COLUMNS FROM `accounts`');
print '<table id="accounts">';
print '<tr>';
while ($row = mysql_fetch_row($cols)) {
print '<th>'.$row[0].'</th>';
}
print '</tr>';
$i = 0;//unneccessary, for CSS classes
while ($row = mysql_fetch_row($data)) {
print '<tr class="'.$i.'">'
$ii = 0; //unneccessary, for CSS classes
foreach ($row as $item) {
print '<td class="'.$i.' '.$ii.'">'.$item.'</td>';
$ii++;
}
print '</tr>';
$i++;
}
print '</table>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment