I am working on a script that will display the staff schedule using PHP and MySQL. I'm using php 5.3.13 and MySQL 5.5.24
What I am trying to do is to populate a table that will have the date and either the staff start time if the status is ACTV, or the status if the staff is either off or on leave.
The code is as follows:
<body>
<center>
<?php
include "../../scripts/php/dbcon/dbcon.php";
$schedule_table = "cc_schedule";
$date_query="SELECT DISTINCT DATE(schedule_date) FROM `$schedule_table`";
$date_result= mysql_query($date_query);
$datenum = mysql_numrows($date_result);
?>
<!-- Table Head -->
<center>
<table cellpadding="0" cellspacing="0">
<tr>
<th><center>No.</center></th>
<th><center>Name</center></th>
<th><center>Employee ID</center></th>
<?php
$d =0;
while ($d < $datenum){
$dt = mysql_result($date_result,$d,"DATE(schedule_date)");
$date = date_create($dt);
$dd = $date;
echo "<th><center>". date_format($dd, 'd-M-Y')."</th><center>";
$d++;
}
?>
</tr>
<!-- Table Body -->
<?php
$names_query="SELECT StaffName, ID
from users
WHERE groupname = 'call center'";
$name_result = mysql_query($names_query);
$namenum = mysql_numrows($name_result);
$schedule_query="SELECT *
FROM `$schedule_table`
ORDER BY `schedule_date` ASC,`sstatus` ASC,`start_time` ASC,`employee_id` ASC";
$schedule_result=mysql_query($schedule_query);
$schedule_num = mysql_numrows($schedule_result);
$n = 1;
while ($n < $namenum){
?>
<tr>
<?php
echo"<td><center>".($n)."</td></center>";
echo"<td><center>".mysql_result($name_result,$n,"StaffName")."</td></center>";
echo"<td><center>".mysql_result($name_result,$n,"ID")."</td></center>";
$d=1;
{
$emp_id = mysql_result($name_result,$n,"ID");
$dt = mysql_result($date_result,$d,"DATE(schedule_date)");
$date = date_create($dt);
$dd = date_format($date, 'Y-m-d');
echo $emp_id;
echo DATE($dd);
while ($d < $datenum) {
$schedule_query ="SELECT *
from $schedule_table
WHERE `employee_id` = $emp_id AND `schedule_date`='$dd'";
$schedule_result = mysql_query($schedule_query);
$schedule = mysql_result($schedule_result,0,"start_time");
$status = mysql_result($schedule_result,0,"sstatus");
if ($status =="ACTV"){
'<td class="'.$status.'"><center>'.$schedule.'</td></center>';
}
else {
echo '<td class="'.$status.'"><center>'.$status."</td></center>";
}
}
$d++;
}
?>
</tr>
<?php
$n++;
}
?>
</table>
</center>
</body>
The code does not return anything. It returns different errors everytime it runs. I suspect that something is wrong with the query. I just can't figure it out..
Any help is appreciated.
Thank You.
Mohamed.