Created
August 3, 2011 15:07
-
-
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
This file contains 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 characters
<?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