Forums
This topic is locked
Calender Problem
Posted 11 Jan 2005 15:27:11
1
has voted
11 Jan 2005 15:27:11 Dean Blackborough posted:
I'm attempting to populate a calender if there is data in a table, works for the most part.// Query
$qu_caldata = "SELECT SDate, EDate, BR FROM villa_rent_cal WHERE VID='$VID'
AND DATE_FORMAT(SDate, '%c')='$Month' ORDER BY SDate ASC";
$rCalData = mysql_query($qu_caldata, $conn_v4) or die(mysql_error());
$row_rCalData = mysql_fetch_assoc($rCalData);
$rows_rCalData = mysql_num_rows($rCalData);
</font id=code></pre id=code>
// Calender - Section 1 - This part work fine
<pre id=code><font face=courier size=2 id=code>
<?php
echo "<table width=\"156\" border=\"0\" cellspacing=\"2\"
cellpadding=\"0\">\n";
echo "<tr>\n";
echo "<td colspan=\"7\" class=\"caltitle\">" . date('F Y',$CalHead)
. "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan=\"7\" height=\"5\">" . "" . "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td width=\"20\" class=\"caldaytitle\">Su</td>\n";
echo "<td width=\"20\" class=\"caldaytitle\">Mo</td>\n";
echo "<td width=\"20\" class=\"caldaytitle\">Tu</td>\n";
echo "<td width=\"20\" class=\"caldaytitle\">We</td>\n";
echo "<td width=\"20\" class=\"caldaytitle\">Th</td>\n";
echo "<td width=\"20\" class=\"caldaytitle\">Fr</td>\n";
echo "<td width=\"20\" class=\"caldaytitle\">Sa</td>\n";
echo "</tr>\n";
echo "<tr>\n";
// Section 2 - This part works fine as well
$DayNum = 1;
$Startrow = 1;
for($Startrow=1;$Startrow<=$calrows;$Startrow++) {
if($Startrow == 1) {
for($Day=0;$Day<7;$Day++) {
if($Day == $FirstDay) {
if(strlen($Month) == 1) { $Month = 0 . $Month; }
if(strlen($DayNum) == 1) { $DayNum = 0 . $DayNum; }
$DayTest = $Year . "-" . $Month . "-" . $DayNum;
if(($DayTest >= $row_rCalData['SDate']) AND
($DayTest <= $row_rCalData['EDate'])) {
$class1 = "booked";
} else {
$class1 = "day";
}
echo "<td class=\"" . $class1 . "\">" . $DayNum . "</td>\n";
$DayNum++;
} else {
if($DayNum > 1) {
if(strlen($Month) == 1) { $Month = 0 . $Month; }
if(strlen($DayNum) == 1) { $DayNum = 0 . $DayNum; }
$DayTest = $Year . "-" . $Month . "-" . $DayNum;
for($u=0;$u<=$rows_rCalData;$u++) {
if(($DayTest >= $row_rCalData['SDate']) AND
($DayTest <= $row_rCalData['EDate'])) {
$class2 = "booked";
} else {
$class2 = "day";
}
}
echo "<td class=\"" . $class2 . "\">" . $DayNum . "</td>\n";
$DayNum++;
} else {
echo "<td>" . " " . "</td>\n";
}
}
}
echo "</tr>\n";
} else {
// Section 3 - This is the section that doesn't work, commented out lines are the problem.
if($Startrow <> $calrows) {
echo "<tr>\n";
for($Day=0;$Day<7;$Day++) {
if(strlen($Month) == 1) { $Month = 0 . $Month; }
if(strlen($DayNum) == 1) { $DayNum = 0 . $DayNum; }
$DayTest = $Year . "-" . $Month . "-" . $DayNum;
## for($v=0;$row_rCalData=mysql_fetch_assoc($rCalData);$v++) { ##
if($DayTest >= $row_rCalData['SDate'] AND
$DayTest <= $row_rCalData['EDate']) {
$class3 = "booked";
} else {
$class3 = "day";
}
## } ##
echo "<td class=\"" . $class3 . "\">" . $DayNum . "</td>\n";
$DayNum++;
}
} else {
Section 4 - This works fine as well
echo "<tr>\n";
for($Day=0;$Day<7;$Day++) {
if($DayNum <= $TotalDays) {
if(strlen($Month) == 1) { $Month = 0 . $Month; }
if(strlen($DayNum) == 1) { $DayNum = 0 . $DayNum; }
$DayTest = $Year . "-" . $Month . "-" . $DayNum;
$row_rCalData = reset($row_rCalData);
for($v=0;$row_rCalData=mysql_fetch_assoc($rCalData);$v++) {
if(($DayTest >= $row_rCalData['SDate']) AND
($DayTest <= $row_rCalData['EDate'])) {
$class4 = "booked";
} else {
$class4 = "day";
}
}
echo "<td class=\"" . $class4 . "\">" . $DayNum . "</td>\n";
$DayNum++;
} else {
echo "<td>" . " " . "</td>\n";
}
}
}
echo "</tr>\n";
}
}
echo "</table>\n";
?>
In section four I just use a for loop to loop through the array to see
if the current date needs to be highlight and it works lovely, produces the below;
<img src="www.galleryof3d.com/site/murc/uploads/working.jpg" border=0>
The problem is when I use the same method to complete section three
it all goes to crap and ends up losing nearlly all the data, as below;
<img src="www.galleryof3d.com/site/murc/uploads/not_working.jpg" border=0>
Anyone got any ideas??
The annoying thing is I actually had it working yesterday but did
something and I haven't been able to get it back. <img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle>
Note: my array has three lots of Data.
2005-01-01 - 2005-01-05
2005-01-14 - 2005-01-18
2005-01-27 - 2005-01-28
--------------------------------------
www.galleryof3d.com
(PHP and MySQL)
Edited by - G3D on 11 Jan 2005 15:29:24
Edited by - G3D on 11 Jan 2005 15:30:37