Hey
I have this piece of code. See how I have tried to make the function display only the header and then by not calling the function with a fourth parameter i tried to only display the appointments. so the time does not come yp 5 times if I call the function 5 times, I tried to use if statements, but somehow the second time when i only call with no 4th parameter i get only the comment text, like this:
http://www.phatasia.com/clients/test.php
please help thanks:
<?php
draw("2004-06-06", "8:00:00", "20:00:00", 1);
draw("2004-06-06", "8:00:00", "20:00:00");
function draw($inDate, $startTime, $endTime, $noHeader = 0)
{
//we may need to connect ourselves or use his existing sql connection here.
$func_link = mysql_connect("localhost", "*****", "*****");
mysql_select_db("dbname", $func_link);
list($hour1, $minute1) = explode(":", $startTime);
list($hour2, $minute2) = explode(":", $endTime);
if ($minute2 < $minute1 && $hour2 < $minute2) {
echo "Invalid times specified";
return;
}
$query = "SELECT * FROM appointments WHERE start_date = '$inDate' ORDER BY start_time ASC";
$result = mysql_query($query);
echo mysql_error();
if (!mysql_num_rows($result)) {
echo "no flights scheduled";
} else {
$numTDs = $hour2 - $hour1;
if ($noHeader) {
//draw head of table
echo "<table border=0 bgcolor=\"#c9c9c9\" bordercolor=\"#000000\" cellpadding=1 cellspacing=0>\n";
echo "<tr>\n";
//draw hour slots as passed in
$temp = $hour1;
for ($i = 0; $i <= $numTDs; $i++) {
echo "<td width=10>$temp</td><td width=10></td>";
$temp++;
}
echo "\n</tr>\n";
}
//end row, now ready to start actual db results
while($data = mysql_fetch_array($result)) {
$stTime = $data['start_time'];
$enTime = $data['end_time'];
list($tmpStHour, $tmpStMin) = explode(":", $stTime);
list($tmpEnHour, $tmpEnMin) = explode(":", $enTime);
echo "\n<tr>\n";
$blankTDs = (($tmpStHour - $hour1) * 2) + ($tmpStMin != "00" ? 1 : 0);
echo "<td colspan=$blankTDs></td>"; //print out the blanks in one simple td, instead of a long loop
//now print out the actual event
$eventSpan = (($tmpEnHour - $tmpStHour) * 2) + ($tmpEnMin != "00" ? 1 : 0) - ($tmpStMin != "00" ? 1 : 0);
echo "<td colspan=$eventSpan bgcolor=\"#999999\">{$data['comment']}</td>";
//event is printed, now we need to echo the rest of the td's until the end of the row.
//there are $i cols, as found above in the for loop.
$numRemaining = $i * 2 - ($eventSpan + $blankTDs);
if ($numRemaining) {
echo "<td colspan=$numRemaining></td>";
}
echo "\n</tr>\n";
}
if ($noHeader) {
echo "</table>\n";
}
}
mysql_close($func_link);
}
?>
Its not for a client, thats the only folder i have access to 🙁
Thanks