NoPHPPhD Posted October 7, 2006 Share Posted October 7, 2006 I went thru the "PHP Calendar Turorial" on this site (Thanks!).Installed Apache, MySQL, etc, works fine.Got the calendar up and going, played around with it to understand what it is doing etc.I also have a database of information that is almost ready to go, it will be MySQL (bunch of rows, several columns)Now, I would like to get it to do something.The calendar has hyperlinks on each of the days.I would like to be able to click on the hyperlink and have a query run (unless better way) that pulls information for that day out of my database.Right now it shows for example:$day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month -1,$d,$year)."\">$d</a>"; What exactly does this line do? Building a link (the <a href) part. Then adding its own path. Then adding the numerical date?Am I going about this wrong? Thought it would be apretty good way to learn...thanks,Snippet of the Calendar from phpfreak..[code]$i = 0; foreach($weeks AS $week){ echo "<tr>\n"; foreach($week as $d){ if($i < $offset_count){ $day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month -1,$d,$year)."\">$d</a>"; echo "<td>$day_link</td>\n"; } if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){ $day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month,$d,$year)."\">$d</a>"; if($date == mktime(0,0,0,$month,$d,$year)){ echo "<td>$d</td>\n"; } else { echo "<td>$day_link</td>\n"; } } elseif(($outset > 0)) { if(($i >= ($num_weeks * 7) - $outset)){ $day_link = "<a href=\"".$_SERVER['PHP_SELF']."?date=".mktime(0,0,0,$month +1,$d,$year)."\">$d</a>"; echo "<td>$day_link</td>\n"; } } $i++; } echo "</tr>\n"; } [/code] Link to comment https://forums.phpfreaks.com/topic/23246-making-the-calendar-do-something/ Share on other sites More sharing options...
NoPHPPhD Posted October 7, 2006 Author Share Posted October 7, 2006 anyone? Link to comment https://forums.phpfreaks.com/topic/23246-making-the-calendar-do-something/#findComment-105523 Share on other sites More sharing options...
redarrow Posted October 7, 2006 Share Posted October 7, 2006 [code]CREATE TABLE room_booking ( `bookID` int(11) NOT NULL auto_increment, `clientID` int(11) NOT NULL , `roomID` int(11) NOT NULL , `arrive` date NOT NULL DEFAULT '0000-00-00', `depart` date NOT NULL DEFAULT '0000-00-00', `nights` int(11) NOT NULL , `discount` varchar(100) NOT NULL , `status` tinyint(1) NOT NULL , PRIMARY KEY(bookID));INSERT INTO room_booking VALUES ('1', '1', '1', '2006-06-30', '2006-07-02', '2', '0', '1');INSERT INTO room_booking VALUES ('2', '2', '1', '2006-07-07', '2006-07-11', '3', '0', '2');INSERT INTO room_booking VALUES ('3', '3', '1', '2006-07-14', '2006-07-17', '2', '0', '1');INSERT INTO room_booking VALUES ('4', '4', '2', '2006-07-07', '2006-07-11', '3', '0', '2');INSERT INTO room_booking VALUES ('5', '1', '2', '2006-07-14', '2006-07-19', '4', '0', '2');INSERT INTO room_booking VALUES ('6', '3', '4', '2006-07-14', '2006-07-29', '14', '0', '3');Calendar scriptCode:<?phpinclude('db.php');$cal_start = isset($_GET['cal_start']) ? $_GET['cal_start'] : mktime(0,0,0);$cal_days = $bookings = array(); // dates for calendar displayfor ($i=0; $i<28; $i++) { $cal_days[] = strtotime("+$i days", $cal_start);} // create room booking arrayfor ($r=1; $r<=4; $r++) { $bookings[$r]=array(); foreach($cal_days as $cd) { $bookings[$r][$cd] = 0; }}$cal_end = end($cal_days); // get bookings for calendar period and put in array$d1 = date('Y-m-d', $cal_start);$d2 = date('Y-m-d', $cal_end);$sql = "SELECT b.bookID, b.clientID, b.roomID, b.arrive, b.depart, b.status FROM room_booking b WHERE ((b.arrive BETWEEN '$d1' AND '$d2') OR (b.depart BETWEEN '$d1' AND '$d2')) ORDER BY b.roomID, b.arrive";$res = mysql_query($sql) or die(mysql_error());while (list($bid, $cid, $rid, $arr, $dep, $stat) = mysql_fetch_row($res)) { for ($d=strtotime($arr); $d<=strtotime("$dep -1 days"); $d+=86400) { if (isset($bookings[$rid][$d])) $bookings[$rid][$d] = $stat; }} // calc prev and next weeks$prevweek = strtotime('-7 days', $cal_start);$nextweek = strtotime('+7 days', $cal_start);function display_calendar (&$dates, &$bookings, $prev, $next) { echo "<table cellspacing='0' cellpadding='0' >\n"; echo "<TR><TH><a href='?cal_start=$prev'><</a></TH> <TH colspan='27'>Fawlty Towers Guest House<br>Room Bookings</TH> <TH><a href='?cal_start=$next'>></a></TH></TR>"; // dates echo "<TR>\n"; echo "<TH>Room</TH>" ; foreach ($dates as $day) { switch (date('w', $day)) { case 0: case 6: $class = 'class=wkend'; break; default: $class = ''; } echo "<TH $class>".date('M', $day).'<br>'.date('j', $day)."</TH>\n"; } echo "</TR>\n"; // rooms foreach ($bookings as $room => $rmdata) { display_room_bookings ($room, $rmdata); } echo "</table><br>\n"; display_key();}function display_room_bookings ($room, $rmdata) { echo "<TR><TH>$room</TH>\n"; foreach ($rmdata as $dt=>$status) { switch ($status) { case 1: $class = 'class=booked'; break; case 2: $class = 'class=conf'; break; case 3: $class = 'class=paid'; break; default: $class = ''; break; } echo "<TD $class> </TD>\n"; }}function display_key() { echo '<table cellspacing="0"> <tr><td>Free</td> <td class="booked">Booked</td> <td class="conf">Confirmed</td> <td class="paid">Paid</td> </tr></table>';}?><html><head><meta name="generator" content="PhpED Version 4.5 (Build 4513)"><title>Sample bookings calendar</title><meta name="author" content="Barand"><meta name="creation-date" content="07/15/2006"><style type='text/css'> table { border-left: 1px solid gray; border-top: 1px solid gray; width: 90%; } th { border-right: 1px solid gray; border-bottom: 1px solid gray; font-family: sans-serif; font-size: 0.75em; font-weight: 700; background-color: #E0E0E0; height : 20px; width: 3.5% } th.wkend { background-color: #C0C0C0; } td { border-right: 1px solid gray; border-bottom: 1px solid gray; font-family: sans-serif; font-size: 0.75em; font-weight: 300; text-align: center; width: 25px; height : 20px; background-color: #C0FFC0; } td.booked { background-color: #FFFFC0; } td.conf { background-color: #DFC868; } td.paid { background-color: #FF8080; }</style></head><body> <?php display_calendar ($cal_days, $bookings, $prevweek, $nextweek)?></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/23246-making-the-calendar-do-something/#findComment-105528 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.