Jump to content

Recommended Posts

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>&lt;</a></td>";
$calendar .="<td colspan=5 align=center>$monthName, $year</td>";
$calendar .="<td><a href=day.php?m=$mn2&y=$yn2&d=$day>&gt;</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'>&nbsp;</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'>&nbsp;</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!!!
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.