sivarts Posted August 26, 2006 Share Posted August 26, 2006 Hi Folks. Wondering if any one can help me out here.I've done a tutorial posted on the Adobe Developer center to build a simple calendar that will 'link' the days that have events to those events. Catch my drift (kinda tired...)? I have gone over the code so many times and even copy/pasted the code from the examples provided from MacroDobia. Basically, I have a recordset that gets all the dates (in MySQL format) for the events (named getEvtDates) and dumps them into an array (see below $dates). I know that the recordset is working and the array is being created (simply with print_r($dates); ) but I still don't have any links in my calendar. Anyone have some time to help me out? It's pretty frustrating...P.S. I am using Dreamweaver to generate most of my code (which I am really good about reading and modifying).Here's the code with some comments...[code]<?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 $getEvtDates; //this is the name of the recordset global $_GET; if (mysql_num_rows($getEvtDates) > 0) { mysql_data_seek($getEvtDates,0); while ($row_getEvtDates = mysql_fetch_assoc($getEvtDates)) { $dates[] = $row_getEvtDates['event_date']; } } /* 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><p><a href=get_days_events.php?y=$yn&m=$mn&d=$day><</a></p></td>"; $calendar .="<td colspan=5 align=center><p><strong>$monthName, $year</strong></p></td>"; $calendar .="<td><p><a href=get_days_events.php?y=$yn2&m=$mn2&d=$day>></a></p></td></tr>"; $calendar .="<tr>"; /* Calendar header: Display the days of the week */ foreach($daysOfWeek as $day) { $calendar .= "<td><p>$day</p></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>"; } $date = $year."-".$month."-".$currentDay; //here's where the trouble might start if (in_array($date,$dates)) { $calendar .= "<td><p><a href='get_days_events.php?y=$year&m=$month&d=$currentDay'>$currentDay</a></p></td>"; } else { $calendar .= "<td><p>$currentDay</p></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); ?>[/code]I know it will be difficult to test this out since you do not have records to play with. But hopefully some one can notice what I am missing. CHEERS (and goodnight!) Quote Link to comment Share on other sites More sharing options...
sivarts Posted August 28, 2006 Author Share Posted August 28, 2006 Can anyone please help?? Quote Link to comment 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.