Jump to content


Photo

My calendar isn't working???


  • Please log in to reply
1 reply to this topic

#1 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 21 September 2006 - 12:44 AM

My calendar just displays the month, year and the SUN-SAT, and not the dates for each month. Every time I place the following code into the code that is underneath the calendar it either displays want I have mentioned above or repeats the calendar down the page. Can someone please tell me why this happening and how I could fix it? Thanks in advance.
$query = "SELECT `booked` FROM `booked` WHERE `entry_date` = '$day_num'";
$result = mysql_query($query) or die ('Query error: '.mysql_error());
while($row = mysql_fetch_array($result)){

require "config2.php";

if(!isset($_GET['date']) || !is_numeric($_GET['date'])){
    $day = date('d', time());
    $month = date('m', time());
    $year = date('Y', time());
}

// else, use the date passed in the q-string:
else{
    $day = date('d', (int)$_GET['date']);
    $month = date('m', (int)$_GET['date']);
    $year = date('Y', (int)$_GET['date']);
}

//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year);

//This gets us the month name
$title = date('F', $first_day);

//Here we find out what day of the week the first day of the month falls on
$day_of_week = date('D', $first_day);

//Once we know what day of the week it falls on, we know how many blank days occur before it. If the first day of the week is a Sunday then it would be zero
switch($day_of_week){
    case "Sun": $blank = 0; break;
    case "Mon": $blank = 1; break;
    case "Tue": $blank = 2; break;
    case "Wed": $blank = 3; break;
    case "Thu": $blank = 4; break;
    case "Fri": $blank = 5; break;
    case "Sat": $blank = 6; break;
}

//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year);

// previous and next links
$previous_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 1){
    $previous_link .= mktime(0,0,0,12,$day,($year -1));
}else{
    $previous_link .= mktime(0,0,0,($month -1),$day,$year);
}
$previous_link .= "\"> Prev</a>";

$next_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=";
if($month == 12){
    $next_link .= mktime(0,0,0,1,$day,($year + 1));
}else{
    $next_link .= mktime(0,0,0,($month +1),$day,$year);
}
$next_link .= "\"> Next</a>";

// Build the heading portion of the calendar table
echo    "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\" width=\"800\">\n".
    "<tr>\n".
    "<td colspan=\"7\">\n".
    "<table align=\"center\">\n".
    "<tr>\n".
    "<td colspan=\"2\" width=\"150\" align=\"left\">$previous_link</td>\n".
    "<td><th colspan=7> $title $year </th></td>".
    "<td colspan=\"2\" width=\"150\" align=\"right\">$next_link</td>\n".
    "</tr>\n".
    "</table>\n".
    "</td>\n".
    "</tr><tr>\n".
    "<td><strong>SUN</strong></td><td><strong>MON</strong></td><td>".
"<strong>TUES</strong></td><td><strong>WED</strong></td><td>".
"<strong>THURS</strong></td><td><strong>FRI</strong></td><td>".
"<strong>SAT</strong></td>\n".
    "</tr><tr>\n";

//This counts the days in the week, up to 7
$day_count = 1;

//first we take care of those blank days
while ( $blank > 0 ){
    echo "<td></td>\n";
    $blank = $blank-1;
    $day_count++;
}

//sets the first day of the month to 1
$day_num = 1;

//count up the days, until we've done all of them in the month
    while($day_num <= $days_in_month ){
$query = "SELECT `booked` FROM `booked` WHERE `entry_date` = '$day_num'";
$result = mysql_query($query) or die ('Query error: '.mysql_error());
while($row = mysql_fetch_array($result)){
        if ($day_count > 7){
            echo "</tr><tr>\n";
            $day_count = 1;
        }

        echo "<td><a href=booked.php?date=".$day_num."> $day_num </a><br />".$row['booked']."</td>\n"; /*Note $r not $rows*/

        $day_num++;
        $day_count++;
    }
}
//Finally we finish out the table with some blank details if needed
while ( $day_count >1 && $day_count <=7 ){
    echo "<td> </td>";
    $day_count++;
}

echo "</tr></table>";

mysql_close();


#2 cturner

cturner
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • LocationMy computer

Posted 21 September 2006 - 08:53 PM

Anyone please help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users