Jump to content


This topic is now archived and is closed to further replies.


My calendar isn't working???

Recommended Posts

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:
    $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
    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));
    $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));
    $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".
    "<td colspan=\"7\">\n".
    "<table align=\"center\">\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".

//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;

//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*/

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

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


Share this post

Link to post
Share on other sites


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.