Emmett Posted August 9, 2007 Share Posted August 9, 2007 I am trying to modify a calendar script so that it colors any day that has an event. The test events are for the 3rd, 7th and 14th but I can only get it to color the 4th, 8th and 15th. have studied hard for the last several days and tried many many variations to no avail. So... Experts: Please give this code a look over and tell me how to make it work right. The if($got){ is what I put in to bring the event to the day of week. The code below is for the 1st 7 days. If I get the answer to this it should work the same for the balance of the month. Thank You // first row shading before the first day $colSpan = $startDay; if ($colSpan > 0) { echo "<td class=\"cal\" bgcolor=\"#CECECE\" colspan=\"$colSpan\" nowrap></td>\n"; } $j = 1; for ($i = $startDay; $i <= 6; $i++) { $qr = 0; // the day = $i, so set a number & query the DB for this day if ($j < 10 AND !ereg("^0",$j)) { $q = "0".$j; } else { $q = $j; } // this is the query results counter $qr = 0; If($got){ echo "<td align=\"center\" nowrap valign=\"top\"> <a href=\"./day.php?LocationID=$LocationID&Date=".$Year."-".$Month."-".$q."\"><b><font color=red>$j</font></b></a>"; $got=""; }else{ echo "<td align=\"center\" nowrap valign=\"top\"> <a href=\"./day.php?LocationID=$LocationID&Date=".$Year."-".$Month."-".$q."\"><b>$j</b></a>"; } $queryDate = $Year."-".$Month."-".$q; $todaysDay = date("w", mktime(0,0,0,$Month, $q, $Year)); // how many of today have happened this month? assume at least one $numOfTodays = 1; if ( date("m", mktime(0,0,0,$Month, $q, $Year)) == date("m", mktime(0,0,0,$Month, ($q - 7), $Year)) ) { $numOfTodays = 2; } if ( date("m", mktime(0,0,0,$Month, $q, $Year)) == date("m", mktime(0,0,0,$Month, ($q - 14), $Year)) ) { $numOfTodays = 3; } if ( date("m", mktime(0,0,0,$Month, $q, $Year)) == date("m", mktime(0,0,0,$Month, ($q - 21), $Year)) ) { $numOfTodays = 4; } if ( date("m", mktime(0,0,0,$Month, $q, $Year)) == date("m", mktime(0,0,0,$Month, ($q - 28), $Year)) ) { $numOfTodays = 5; } // we need to pre-query and then sort // query the CalendarDaily table $result = mysql("$DBName","SELECT CalendarDetailsID FROM phpCalendar_Daily WHERE ".$LocQuery." AND Active = '1' AND ( ('$queryDate' = StartDate AND StopDate = '0000-00-00') OR (StopDate != '0000-00-00' AND '$queryDate' BETWEEN StartDate AND StopDate) )") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $gotResults[$qr] = $row[0]; $qr++; } // query the CalendarWeekly table $result = mysql("$DBName","SELECT CalendarDetailsID, DaysOfWeek FROM phpCalendar_Weekly WHERE ".$LocQuery." AND Active = '1' AND ( ('$queryDate' >= DisplayStart AND DisplayStop = '0000-00-00') OR (DisplayStop != '0000-00-00' AND '$queryDate' BETWEEN DisplayStart AND DisplayStop) )") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $CalendarDetailsID = $row[0]; $DaysOfWeek = $row[1]; if ($DaysOfWeek == $todaysDay) { $gotResults[$qr] = $CalendarDetailsID; $qr++; } else { $split = explode("|", $DaysOfWeek); for ($x = 0; $split[$x]; $x++) { if ($split[$x] == $todaysDay) { $gotResults[$qr] = $CalendarDetailsID; $qr++; } } while ($split[0]) { array_pop($split); } } } // query the CalendarMonthly table $result = mysql("$DBName","SELECT CalendarDetailsID FROM phpCalendar_Monthly WHERE ".$LocQuery." AND Active = '1' AND DayOfMonth = '$q' AND ( ('$queryDate' >= DisplayStart AND DisplayStop = '0000-00-00') OR (DisplayStop != '0000-00-00' AND '$queryDate' BETWEEN DisplayStart AND DisplayStop) )") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $gotResults[$qr] = $row[0]; $qr++; } // query the CalendarYearly table $result = mysql("$DBName","SELECT CalendarDetailsID FROM phpCalendar_Yearly WHERE ".$LocQuery." AND Active = '1' AND DayOfMonth = '$q' AND Month = '$Month' AND ( ('$queryDate' >= DisplayStart AND DisplayStop = '0000-00-00') OR (DisplayStop != '0000-00-00' AND '$queryDate' BETWEEN DisplayStart AND DisplayStop) )") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $gotResults[$qr] = $row[0]; $qr++; } // query the CalendarPeriodicalMonthly table $result = mysql("$DBName","SELECT CalendarDetailsID, WeekDays FROM phpCalendar_PeriodicalMonthly WHERE ".$LocQuery." AND Active = '1' AND WeekNumber = '$numOfTodays' AND ( ('$queryDate' >= DisplayStart AND DisplayStop = '0000-00-00') OR (DisplayStop != '0000-00-00' AND '$queryDate' BETWEEN DisplayStart AND DisplayStop) )") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $CalendarDetailsID = $row[0]; $WeekDays = $row[1]; if ($WeekDays == $todaysDay) { $gotResults[$qr] = $CalendarDetailsID; $qr++; } else { $split = explode("|", $WeekDays); for ($x = 0; $split[$x]; $x++) { if ($split[$x] == $todaysDay) { $gotResults[$qr] = $CalendarDetailsID; $qr++; } } while ($split[0]) { array_pop($split); } } } // query the CalendarPeriodicalYearly table $result = mysql("$DBName","SELECT CalendarDetailsID, WeekDays FROM phpCalendar_PeriodicalYearly WHERE ".$LocQuery." AND Active = '1' AND WeekNumber = '$numOfTodays' AND Month = '$Month' AND ( ('$queryDate' >= DisplayStart AND DisplayStop = '0000-00-00') OR (DisplayStop != '0000-00-00' AND '$queryDate' BETWEEN DisplayStart AND DisplayStop) )") or die(mysql_error()); while ($row = mysql_fetch_row($result)) { $CalendarDetailsID = $row[0]; $WeekDays = $row[1]; if ($WeekDays == $todaysDay) { $gotResults[$qr] = $CalendarDetailsID; $qr++; } else { $split = explode("|", $WeekDays); for ($x = 0; $split[$x]; $x++) { if ($split[$x] == $todaysDay) { $gotResults[$qr] = $CalendarDetailsID; $qr++; } } while ($split[0]) { array_pop($split); } } } for ($g = 0; $gotResults[$g]; $g++) { $query .= " OR CalendarDetailsID = '$gotResults[$g]'"; } while ($gotResults[0]) { array_pop($gotResults); } // If an event was found if ($query) { $query = "(".ereg_replace("^ OR ","",$query).")"; $result = mysql("$DBName","SELECT Title, CalendarDetailsID FROM phpCalendar_Details WHERE $query ORDER BY StartTime, StopTime") or die(mysql_error()); // Then... while ($row = mysql_fetch_row($result)) { $CDTi = $row[0]; $CDCI = $row[1]; $len = strlen($CDTi); if ($len > ($glbl_TruncateLength + 3)) { $showName = substr($CDTi,0,$glbl_TruncateLength)."..."; } else { $showName = $CDTi; } if ($ver >= 4) { getEventIE($CDCI, $CDTi, "", $queryDate); } else { getEvent($CDCI, "", $queryDate); } } $got="hit"; } $query = ""; echo "</td>"; $j++; } Quote Link to comment https://forums.phpfreaks.com/topic/64036-solved-im-just-learning-need-a-little-help-to-complete-a-modifiction/ Share on other sites More sharing options...
Emmett Posted August 11, 2007 Author Share Posted August 11, 2007 Well - Well - Well, I finally figured out the answer to my phpCalendar modification. Move the control code: If($got){ echo "<td align=\"center\" nowrap valign=\"top\"> <a href=\"./day.php?LocationID=$LocationID&Date=".$Year."-".$Month."-".$q."\"><b><font color=red>$j</font></b></a>"; }else{ echo "<td align=\"center\" nowrap valign=\"top\"> <a href=\"./day.php?LocationID=$LocationID&Date=".$Year."-".$Month."-".$q."\"><b>$j</b></a>"; } to the bottom of this for loop: for ($i = $startDay; $i <= 6; $i++) { to just above these lines: $query = ""; echo "</td>"; $j++; } And finally put the "if" control variable in this location: $got=""; if ($query) { $got="hit"; Do the same proceedure for both the "first week" and "remaining weeks" which are two seperate code blocks. Now it works exactly as desired and I can go on to creating the css class to replace the <font> stuff with "highlighting" instead of just a color on the event days. Here is a snapshot of the results so far: Quote Link to comment https://forums.phpfreaks.com/topic/64036-solved-im-just-learning-need-a-little-help-to-complete-a-modifiction/#findComment-321248 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.