Created
May 24, 2016 20:33
-
-
Save ohaal/13c0ffee81653e725282184ba6dcaa53 to your computer and use it in GitHub Desktop.
Simple MySQL query to HTML
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 characters
function queryToHtml($mysqli, $query) { | |
if ($result = $mysqli->query($query)) { | |
/* Get field information for all columns */ | |
$finfo = $result->fetch_fields(); | |
// Print headers | |
print('<table><tr>'); | |
foreach ($finfo as $val) { | |
printf('<th>%s</th>', $val->name); | |
} | |
print('</tr>'); | |
// Print row contents | |
while ($row = $result->fetch_row()) { | |
print('<tr>'); | |
foreach ($row as $col) { | |
printf('<td>%s</td>', $col); | |
} | |
print('</tr>'); | |
} | |
print('</table>'); | |
$result->free(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment