Print MySQL Query
5
This is a little function that you can use to print out results of a query. It will dynamicly generate the table for you (like phpMyAdmin). This is a nice little checker that is fast. It beats logging into phpMyAdmin and typing in your query there.
I will use the config.php and class.mysql.php files from MySQL DB Class with Extras, so please look at those also.
I will use the config.php and class.mysql.php files from MySQL DB Class with Extras, so please look at those also.
<?php
require_once "config.php";
require_once "class.mysql.php";
$db = new mysql();
function printQuery($sql){
global $db;
echo $db->numRowsQ($sql)." Rows<br />";
echo "<table border=1>";
$export = $db->query($sql);
$fields = $db->numFields($export);
$header = "\n<tr>\n";
for ($i = 0; $i < $fields; $i++) {
$header .= "<td>".$db->fieldName($export, $i) . "</td>";
}
$header .= "\n</tr>\n";
while($row = $db->fetchRow($export)) {
$line = '';
$data .= "\n<tr>\n";
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "<td><i>NULL</i></td>";
} else {
$value = str_replace('"', '""', $value);
$value = '<td>' . $value . "</td>";
}
$value = stripslashes($value);
$line .= $value;
}
$data .= trim($line);
$data .= "\n<tr>\n";
}
echo $header;
echo $data;
echo "</table>";
}
$sql = "SELECT * FROM users";
printQuery($sql);
$sql = "SELECT first_name, last_name, username, password FROM users";
printQuery($sql);
?>






I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?
MiramarDesign