sivarts Posted August 24, 2006 Share Posted August 24, 2006 Hello fellow freaks-I have built the calendar using the following tutorial on the Dreamweaver developer site: Building a Blog with DW, PHP and MySQL Part three:Creating a search feature and archiving your blog.I built the claendar and it works fine, but the dates that have records (taken from a recordset and dumped into an array) do not become links as they should. I have been racking my brains over this for too long now and I just can't figure it out. Plus two of my variable are not set which gives me two errors.Heres the code for the function:<?php function build_calendar($month,$year,$day) { /* Declaring the variables */ $daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa'); $firstDayOfMonth = mktime(0,0,0,$month,1,$year); $noDays = date('t',$firstDayOfMonth); $dateComponents = getdate($firstDayOfMonth); $dayOfWeek = $dateComponents['wday']; $monthName = date('F',mktime(0,0,0,$month,1,$year)); global $rsArticleDates; global $_GET; if (mysql_num_rows($rsArticleDates) > 0){ mysql_data_seek($rsArticleDates,0); while($row_rsArticleDates = mysql_fetch_assoc($rsArticleDates)){ [b]$dates[][/b] = $row_rsArticleDates['ArticleDate']; } } /* Computing the previous month. */ if($month == 1) { $mn=12; $yn=$year-1; } else { $mn=$month-1; $yn=$year; } /* Computing the next month. */ if($month == 12) { $mn2=1; $yn2=$year+1; } else { $mn2=$month+1; $yn2=$year; } /* Calendar header: next and previous month links */ $calendar = "<table>"; $calendar .= "<tr><td><a href=day.php?m=$mn&y=$yn&d=$day><</a></td>"; $calendar .="<td colspan=5 align=center>$monthName, $year</td>"; $calendar .="<td><a href=day.php?m=$mn2&y=$yn2&d=$day>></a></td></tr>"; $calendar .="<tr>"; /* Calendar header: Display the days of the week */ foreach($daysOfWeek as $day) { $calendar .= "<td>$day</td>"; } $calendar .= "</tr>"; $calendar .= "<tr>"; $currentDay = 1; /* Fill in the beginning of the calendar body */ if ($dayOfWeek > 0) { $calendar .= "<td colspan='$dayOfWeek'> </td>"; } /* Generate the calendar body */ while ($currentDay <= $noDays) { if ($dayOfWeek == 7) { $dayOfWeek = 0; $calendar .= "</tr><tr>"; } [b]$date = [/b]$year."-".$month."-".$currentDay; if (in_array($date,$dates)) { $calendar .= "<td><a href='day.php?m=$month&y=$year&d=$currentDay'>$currentDay</a></td>"; } else { $calendar .= "<td>$currentDay</td>"; } $currentDay++; $dayOfWeek++; } /* Filling in the end of the calendar body */ if ($dayOfWeek != 7) { $remainingDays = 7 - $dayOfWeek; $calendar .= "<td colspan='$remainingDays'> </td>"; } $calendar .= "</table>"; return $calendar;} if (isset($_GET['m']) && isset($_GET['y']) && isset($_GET['d'])){ $month = $_GET['m']; $year = $_GET['y']; $day = $_GET['d'];} else { $dateComponents = getdate(); $month = $dateComponents['mon']; $year = $dateComponents['year']; $day = $dateComponents['mday'];}echo build_calendar($month,$year,$day); ?>The two variables on BOLD are the errors (undefined variable). Has anyone done this tut or know what is wrong with the code? I know my recordset is giving valid results (I have tested it).Any help would be much appreciated!!! Link to comment https://forums.phpfreaks.com/topic/18588-php-calendar-with-clickable-dates-_not-working/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.