I'm working on a generic query viewer, and I have one last problem to solve.
Suppose I have a query that returns the following data...
| Job Code | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
--------------------------------------------------------
| 1234-567 | 0 | 3 | 2 | 5 | 2 | 0 | 0 |
| 3214-431 | 0 | 2 | 4 | 3 | 0 | 0 | 0 |
... and so on. When I run the code below, I get the following result in my browser. It looks like the associative array is being filled twice. I've seen this when I do the fetch array with MYSQLI_BOTH, but I should be getting just the associtive array with the code below.
| Job Code | Mon | Tue | Wed | Thu | Fri | Sat | Sun | Job Code | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
--------------------------------------------------------
| 1234-567 | 0 | 3 | 2 | 5 | 2 | 0 | 0 |
| 3214-431 | 0 | 2 | 4 | 3 | 0 | 0 | 0 |
Code...
function query2table( $dbcon, $query )
{
// Connection is already made.
$queryResult = mysqli_query($dbcon, $query);
if( $queryResult )
{
echo "<TABLE cellpadding='5' cellspacing='1' border='1'><THEAD><TR>
";
while ($hdrrow = mysqli_fetch_assoc($queryResult) )
{
foreach ($hdrrow as $hdr => $value) {
echo "<th>";
echo $hdr;
echo "</th>";
}
}
echo "</TR></THEAD>
";
mysqli_data_seek($queryResult, 0);
while ($row = mysqli_fetch_assoc($queryResult,MYSQLI_NUM))
{
foreach( $row as $cell )
{
echo "<TD>$cell</TD>";
}
echo " </TR>
";
}
echo "</TABLE>
";
} else {
$error = mysqli_error($dbcon);
echo "
<BR><BR>dbi_displayQuery - Error reading database: $error<BR><BR>
";
}
}
Ideas?