cturner Posted November 15, 2006 Share Posted November 15, 2006 My calendar is suppose to display booked out after the user clicks on a date and it doesn't. Can someone please look at my code and tell me why this is happening. Thanks in advance.Here is my code that I am working with:[code=php:0]//count up the days, until we've done all of them in the monthwhile ( $day_num <= $days_in_month ){$sql = mysql_query("SELECT * FROM booked WHERE entry_day = $day AND entry_month = $month AND entry_year = $year") or die("Could not query because: ".mysql_error());$row = mysql_fetch_assoc($sql);echo "<td><a href=booked.php?entry_date=$day_num&entry_month=$title&entry_year=$year>$day_num</a><br>".$row['booked']."</td>";$day_num++;$day_count++;//Make sure we start a new row every weekif ($day_count > 7){echo "</tr><tr>";$day_count = 1;}}[/code] Link to comment https://forums.phpfreaks.com/topic/27293-not-displaying-booked-out/ Share on other sites More sharing options...
doni49 Posted November 15, 2006 Share Posted November 15, 2006 How can we do that? This code seems to show how you BUILD the form. Where's the code that deals with the user's "click"? Link to comment https://forums.phpfreaks.com/topic/27293-not-displaying-booked-out/#findComment-124804 Share on other sites More sharing options...
cturner Posted November 15, 2006 Author Share Posted November 15, 2006 Okay I will post the whole code here.This code is the display the calendar and where it is booked out:[code=php:0]require "config2.php";$date = (isset($_GET['date']))?$_GET['date']:time();//This puts the day, month, and year in seperate variables$day = date('d', $date);$month = date('m', $date);$year = date('Y', $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 occure 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);// next and previous 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>";//Here we start building the table headsecho "<table border=1 width=294>";echo "<tr><th colspan=7>$previous_link $title $year $next_link</th></tr>";echo "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr>";//This counts the days in the week, up to 7$day_count = 1;echo "<tr>";//first we take care of those blank dayswhile ( $blank > 0 ){echo "<td></td>";$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 monthwhile ( $day_num <= $days_in_month ){$sql = mysql_query("SELECT * FROM booked WHERE entry_day = $day AND entry_month = $month AND entry_year = $year") or die("Could not query because: ".mysql_error());$row = mysql_fetch_assoc($sql);echo "<td><a href=booked.php?entry_date=$day_num&entry_month=$title&entry_year=$year>$day_num</a><br>".$row['booked']."</td>";$day_num++;$day_count++;//Make sure we start a new row every weekif ($day_count > 7){echo "</tr><tr>";$day_count = 1;}}//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]This code is to add booked out to the database:[code=php:0]require "config2.php";// get the date from the booking calendar$entry_day = $_GET['entry_day'];$entry_month = $_GET['entry_month'];$entry_year = $_GET['entry_year'];$booked = "Booked out";// insert the date into the database$insert = "INSERT INTO booked (`id`, `entry_day`, `entry_month`, `entry_year`, `booked`) VALUES (0, '$entry_day', '$entry_month', '$entry_year', '$booked')" or die ("Could not select the table because: ".mysql_error());if (mysql_query ($insert)) { echo "<a href=calendar_test.php>Click here</a> to continue";} else { print "Could not add the entry because: ".mysql_error(). ". The query was $insert.";}mysql_close();[/code] Link to comment https://forums.phpfreaks.com/topic/27293-not-displaying-booked-out/#findComment-124805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.