I'm using this code to connect to a mysql db but i get only the first
row from the query.I don't know where's the mistake.Can someone help me with this?
The code:
if(!($result = mysql_query("select distinct emp_name FROM overtime_hours order by emp_name", $dbi))){
print("MySQL reports: " . mysql_error() . "\n");
exit();
}
$qx = "SELECT ovtime_date";
while($rowx = mysql_fetch_object($result)) {
$qx .= ", IF(emp_name = '$rowx->emp_name', ovtime_hours, 0) AS 'Date'";
}
//$qx .= ", SUM(ovtime_hours) AS \"Total Hours\" ";
$qx .= "FROM overtime_hours ";
$qx .= "GROUP BY ovtime_date";
if(!($dbx = mysql_query($qx, $dbi))){
print("MySQL reports: " . mysql_error() . "\n");
exit();
}
?>
<table border="1">
<tr>
<td bgcolor="#FFFFCC"></td>
<?php
mysql_data_seek($result, 0);
while($rowx = mysql_fetch_object($result)){
print("<td bgcolor=\"#FFFFCC\">");
print("$rowx->emp_name");
print("</td>");
}
?>
</tr>
<?php
while($dbrow = mysql_fetch_row($dbx)) {
print("<tr>");
$col_num = 0;
foreach($dbrow as $key=>$value){
if($dbrow[$col_num] > 0){
print("<td>$dbrow[$col_num]</td>");
}
else {
print("<td> </td>");
}
$col_num++;
}
print("</tr>\n");
}
?>
</table>