JamieFuller
Programmer
Hi Guys,
I have been asked to write a 'wallboard' script that shows where all our engineers are scheduled to be between 2 dates...
the problem is my code is pretty shite,
It works and it works well but it is super slow. and if I try to do more than 14 or so days I might as well go and make tea.
currently I read a table to get a list of all engineers, I then read from 3 seperate tables for each day and each engineer.
there has got to be a better way, any ideas?
<?
echo "<table border=\"0\" width=\"100%\" class=\"bdr\" cellpadding=\"2\" cellspacing=\"0\"><tr bgcolor=\"#aaaaaa\"><td>Engineer</td>";
for ($dt3=$dt1;$dt3<$dt2;$dt3+=86400)
{
echo "<td align=\"center\">".date("l",$dt3)."<br>".date("d-M",$dt3)."</td>";
}
echo "</tr>";
$query = "SElect * FROM MstEngineer;";
$query= mssql_query($query);
//echo "<table border=\"0\" width=\"100%\" class=\"bdr\">";
$c=0;
while($row = mssql_fetch_array($query)) {
$eid=$row[0];
$name=$row[2]." ".$row[1];
echo "<tr><td class=\"bdr2\" valign=\"top\">$row[1] $row[2]</td>";
for ($dt3=$dt1;$dt3<$dt2;$dt3+=86400)
{
$jones="";
$dt5=date("D",$dt3);
$bg="";
if (($dt5=="Sat"||($dt5=="Sun") $bg=" bgcolor =\"#dddddd\"";
$dt4=date("Y-m-d",$dt3);
echo "<td class=\"bdr2\"$bg>";
$query2 = "SElect * FROM VIEW_IS_Calendar_details WHERE EngineerId=$eid and visited='$dt4';";
$query2= mssql_query($query2);
while($row2 = mssql_fetch_array($query2)) {
$jones.= $row2[0]." ".$row2[1]."<br>";
}
$query2 = "SElect OffType FROM viewholiday WHERE EngineerID=$eid and ('$dt4' BETWEEN startdate and enddate);";
$query2= mssql_query($query2);
while($row2 = mssql_fetch_array($query2)) {
$jones.= $row2[0]."<br>";
}
$query2 = "SElect LocationDesc FROM viewinstallation WHERE EngineerID=$eid and ('$dt4' BETWEEN startdate and enddate);";
$query2= mssql_query($query2);
while($row2 = mssql_fetch_array($query2)) {
$jones.= $row2[0]."<br>";
}
if($jones==""$jones=" ";
echo $jones;
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
Any ideas for optimisation would be great!
Kindest Regards
Jamie
I have been asked to write a 'wallboard' script that shows where all our engineers are scheduled to be between 2 dates...
the problem is my code is pretty shite,
It works and it works well but it is super slow. and if I try to do more than 14 or so days I might as well go and make tea.
currently I read a table to get a list of all engineers, I then read from 3 seperate tables for each day and each engineer.
there has got to be a better way, any ideas?
<?
echo "<table border=\"0\" width=\"100%\" class=\"bdr\" cellpadding=\"2\" cellspacing=\"0\"><tr bgcolor=\"#aaaaaa\"><td>Engineer</td>";
for ($dt3=$dt1;$dt3<$dt2;$dt3+=86400)
{
echo "<td align=\"center\">".date("l",$dt3)."<br>".date("d-M",$dt3)."</td>";
}
echo "</tr>";
$query = "SElect * FROM MstEngineer;";
$query= mssql_query($query);
//echo "<table border=\"0\" width=\"100%\" class=\"bdr\">";
$c=0;
while($row = mssql_fetch_array($query)) {
$eid=$row[0];
$name=$row[2]." ".$row[1];
echo "<tr><td class=\"bdr2\" valign=\"top\">$row[1] $row[2]</td>";
for ($dt3=$dt1;$dt3<$dt2;$dt3+=86400)
{
$jones="";
$dt5=date("D",$dt3);
$bg="";
if (($dt5=="Sat"||($dt5=="Sun") $bg=" bgcolor =\"#dddddd\"";
$dt4=date("Y-m-d",$dt3);
echo "<td class=\"bdr2\"$bg>";
$query2 = "SElect * FROM VIEW_IS_Calendar_details WHERE EngineerId=$eid and visited='$dt4';";
$query2= mssql_query($query2);
while($row2 = mssql_fetch_array($query2)) {
$jones.= $row2[0]." ".$row2[1]."<br>";
}
$query2 = "SElect OffType FROM viewholiday WHERE EngineerID=$eid and ('$dt4' BETWEEN startdate and enddate);";
$query2= mssql_query($query2);
while($row2 = mssql_fetch_array($query2)) {
$jones.= $row2[0]."<br>";
}
$query2 = "SElect LocationDesc FROM viewinstallation WHERE EngineerID=$eid and ('$dt4' BETWEEN startdate and enddate);";
$query2= mssql_query($query2);
while($row2 = mssql_fetch_array($query2)) {
$jones.= $row2[0]."<br>";
}
if($jones==""$jones=" ";
echo $jones;
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
Any ideas for optimisation would be great!
Kindest Regards
Jamie