Forums

PHP

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>
&lt;?php
echo "&lt;table width=\"156\" border=\"0\" cellspacing=\"2\"
cellpadding=\"0\"&gt;\n";
echo "&lt;tr&gt;\n";
echo "&lt;td colspan=\"7\" class=\"caltitle\"&gt;" . date('F Y',$CalHead)
. "&lt;/td&gt;\n";
echo "&lt;/tr&gt;\n";
echo "&lt;tr&gt;\n";
echo "&lt;td colspan=\"7\" height=\"5\"&gt;" . "" . "&lt;/td&gt;\n";
echo "&lt;/tr&gt;\n";
echo "&lt;tr&gt;\n";
echo "&lt;td width=\"20\" class=\"caldaytitle\"&gt;Su&lt;/td&gt;\n";
echo "&lt;td width=\"20\" class=\"caldaytitle\"&gt;Mo&lt;/td&gt;\n";
echo "&lt;td width=\"20\" class=\"caldaytitle\"&gt;Tu&lt;/td&gt;\n";
echo "&lt;td width=\"20\" class=\"caldaytitle\"&gt;We&lt;/td&gt;\n";
echo "&lt;td width=\"20\" class=\"caldaytitle\"&gt;Th&lt;/td&gt;\n";
echo "&lt;td width=\"20\" class=\"caldaytitle\"&gt;Fr&lt;/td&gt;\n";
echo "&lt;td width=\"20\" class=\"caldaytitle\"&gt;Sa&lt;/td&gt;\n";
echo "&lt;/tr&gt;\n";
echo "&lt;tr&gt;\n";

// Section 2 - This part works fine as well
$DayNum = 1;
$Startrow = 1;
for($Startrow=1;$Startrow&lt;=$calrows;$Startrow++) {
if($Startrow == 1) {
for($Day=0;$Day&lt;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 &gt;= $row_rCalData['SDate']) AND
($DayTest &lt;= $row_rCalData['EDate'])) {
$class1 = "booked";
} else {
$class1 = "day";
}
echo "&lt;td class=\"" . $class1 . "\"&gt;" . $DayNum . "&lt;/td&gt;\n";
$DayNum++;
} else {
if($DayNum &gt; 1) {
if(strlen($Month) == 1) { $Month = 0 . $Month; }
if(strlen($DayNum) == 1) { $DayNum = 0 . $DayNum; }
$DayTest = $Year . "-" . $Month . "-" . $DayNum;
for($u=0;$u&lt;=$rows_rCalData;$u++) {
if(($DayTest &gt;= $row_rCalData['SDate']) AND
($DayTest &lt;= $row_rCalData['EDate'])) {
$class2 = "booked";
} else {
$class2 = "day";
}
}
echo "&lt;td class=\"" . $class2 . "\"&gt;" . $DayNum . "&lt;/td&gt;\n";
$DayNum++;
} else {
echo "&lt;td&gt;" . " " . "&lt;/td&gt;\n";
}
}
}
echo "&lt;/tr&gt;\n";
} else {

// Section 3 - This is the section that doesn't work, commented out lines are the problem.
if($Startrow &lt;&gt; $calrows) {
echo "&lt;tr&gt;\n";
for($Day=0;$Day&lt;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 &gt;= $row_rCalData['SDate'] AND
$DayTest &lt;= $row_rCalData['EDate']) {
$class3 = "booked";
} else {
$class3 = "day";
}
## } ##
echo "&lt;td class=\"" . $class3 . "\"&gt;" . $DayNum . "&lt;/td&gt;\n";
$DayNum++;
}
} else {

Section 4 - This works fine as well
echo "&lt;tr&gt;\n";
for($Day=0;$Day&lt;7;$Day++) {
if($DayNum &lt;= $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 &gt;= $row_rCalData['SDate']) AND
($DayTest &lt;= $row_rCalData['EDate'])) {
$class4 = "booked";
} else {
$class4 = "day";
}
}
echo "&lt;td class=\"" . $class4 . "\"&gt;" . $DayNum . "&lt;/td&gt;\n";
$DayNum++;
} else {
echo "&lt;td&gt;" . " " . "&lt;/td&gt;\n";
}
}
}
echo "&lt;/tr&gt;\n";
}
}
echo "&lt;/table&gt;\n";
?&gt;

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

Reply to this topic