cturner Posted September 21, 2006 Share Posted September 21, 2006 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.[code]$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)){[/code][code]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 zeroswitch($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 tableecho "<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 dayswhile ( $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 neededwhile ( $day_count >1 && $day_count <=7 ){ echo "<td> </td>"; $day_count++;}echo "</tr></table>";mysql_close();[/code] Link to comment https://forums.phpfreaks.com/topic/21482-my-calendar-isnt-working/ Share on other sites More sharing options...
cturner Posted September 21, 2006 Author Share Posted September 21, 2006 Anyone please help. Link to comment https://forums.phpfreaks.com/topic/21482-my-calendar-isnt-working/#findComment-96334 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.