<?
$query= "
SELECT
job_colour,
job_date,
job_time_slot,
cust_surname,
job_desc,
job_location,
job_type
from
job
WHERE
job_completed = 'No'
ORDER BY
job_date asc";
$result = mysql_query($query);
$jobs = array();
while ($row = mysql_fetch_assoc($result)){
$tmp = $row;
unset($tmp[job_date]);
$jobs[$row['job_date']][]=$tmp;
}
$dates = array_keys($jobs);
if (count($dates) === 0){
$curDate = $end = time();
} else {
$curDate = strtotime($dates[0]);
$end = strtotime($dates[count($dates)-1]);
}
$dates = null;
echo <<<HTML
<table>
<tr>
<th align="center">Status</th>
<th align="center">Job Date</th>
<th align="left">Time Slot</th>
<th align="left">Customer</th>
<th align="left">Desc</th>
<th align="left">Location</th>
<th align="center">Type</th>
<th align="center">Allocated</th>
<th align="center">Free</th>
<th align="center">Actions</th>
</tr>
HTML;
$style = "style1";
while ($curDate <= $end){
$displayDate = date ("Y-m-d", $curDate);
if (isset($jobs[$displayDate])){
$curJobs = $jobs;
$allocation = getContent("installer.php");
$free = getContent("free.php");
}else{
$curJobs['job_colour'] =
$curJobs['job_time_slot'] =
$curJobs['cust_surname'] =
$curJobs['job_desc'] =
$curJobs['job_location'] =
$curJobs['job_type'] =
$allocation =
$free = " ";
}
foreach ($curJobs as $job){
echo <<<HTML
<tr class="$style">
<td>{$job['job_colour']}</td>
<td>$displayDate</td>
<td>{$job['job_time_slot']}</td>
<td>{$job['cust_surname']}</td>
<td>{$job['job_desc']}</td>
<td>{$job['job_location']}</td>
<td>{$job['job_type']}</td>
<td>$allocation</td>
<td>$free</td>
<td>PUT SOME BUTTONS HERE</td>
</tr>
HTML;
} //end of foreach loop
$style = ($style=="style1") ? "style2" : "style1";
$curDate = strtotime("+1 day", $curDate);
} //end of while loop
echo "</table>";
function getContents($file){
ob_start();
include $file;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
?>