I keep on getting blank pages with my calendar???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

I keep on getting blank pages with my calendar???

Post by cturner »

Where should I place the following code into the code that is below that?

Code: Select all

$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)) {
I have tried to place the above code in many places but I get blank pages. :?

Code: Select all

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 ){
        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>";
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

What information are you pulling out of the database and where do you expect it to appear. Do you have a live site that we could look at?
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Post by cturner »

Booked out is suppose to display underneath a day in the calendar after a user has clicked on a day. The live site is here: http://blueguminteractive.biz/guestbook/test2.php.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Just in case it's not just a typo you made when you posted the message to the forum, there's a double quote missing from the end of the SQL statement so it should be:

Code: Select all

$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)) {
not

Code: Select all

$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)) {
Mac
Post Reply