Skip to content

Instantly share code, notes, and snippets.

@hlorand
Created March 7, 2016 19:37
Show Gist options
  • Save hlorand/e505c4fdf44315dc2fa0 to your computer and use it in GitHub Desktop.
Save hlorand/e505c4fdf44315dc2fa0 to your computer and use it in GitHub Desktop.
function mysqltable_to_htmltable($table) {
global $conn;
$result0 = mysqli_query($conn,'SHOW COLUMNS FROM '.$table) or die('cannot show columns from '.$table);
$result = mysqli_query($conn,'SELECT * FROM '.$table) or die('cannot show columns from '.$table);
if(mysqli_num_rows($result0) && mysqli_num_rows($result)) {
echo '<table cellpadding="5" cellspacing="0" border="1">';
while($row0 = mysqli_fetch_row($result0)) {
echo '<th>';
echo $row0[0];
echo '</th>';
}
while($row = mysqli_fetch_row($result)) {
echo '<tr>';
foreach($row as $key=>$value) {
echo '<td>',$value,'</td>';
}
echo '</tr>';
}
echo '</table><br />';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment