ChompGator Posted July 22, 2008 Share Posted July 22, 2008 Hello, I have a calendar on one of the pages of my site...Right now the Calendar shows an event on the day you hover your mouse over... What Id like it to do: Is allow clicking on the days that have an event scheduled then have a pop-up window appear with the event information. -Im just unsure how I alter my code to get that to happen, here is the code below, any tips would be great <?php $host="*"; // Host name $username="*"; // Mysql username $password="*"; // Mysql password $db_name="*"; // Database name $tbl_name="*"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n'); $currYear = isset($_GET['year']) ? $_GET['year'] : date('Y'); # Sample "events" table # +----+---------------------+------------+ # | id | title | event_date | # +----+---------------------+------------+ # | 1 | County show | 2008-04-25 | # | 2 | Pop concert | 2008-05-01 | # | 3 | Jazz Fest | 2008-04-27 | # | 4 | Dentist appointment | 2008-04-25 | # +----+---------------------+------------+ /**** * get this months events and store in array */ $sql = "SELECT DAY(event_date) as day, GROUP_CONCAT(title SEPARATOR '\n') as titles FROM events WHERE MONTH(event_date)=$currMonth AND YEAR(event_date) = $currYear GROUP BY day"; $res = mysql_query($sql); while (list($d, $t) = mysql_fetch_row($res)) { $events[$d] = $t; } $today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0; $prevMonth = $currMonth==1 ? 12 : $currMonth-1; $nextMonth = $currMonth==12? 1 : $currMonth+1; $prevYear = $currMonth==1 ? $currYear-1 : $currYear; $nextYear = $currMonth==12? $currYear+1 : $currYear; $day1 = mktime(0,0,0,$currMonth,1,$currYear); $dim = date('t', $day1); $dayN = mktime(0,0,0,$currMonth,$dim,$currYear); $dow1 = (date('w',$day1)+6) % 7; $dowN = (date('w',$dayN)+6) % 7; $calHead = date('F Y',$day1); echo <<<EOT <table border="0" cellspacing="1" style="border: 1pt solid silver"> <tr> <td class="hd"><a class="nul" href="$_SERVER[php_SELF]?year=$prevYear&month=$prevMonth"><<</a></td> <td colspan="5" class="hd">$calHead</td> <td class="hd"><a class="nul" href="$_SERVER[php_SELF]?year=$nextYear&month=$nextMonth">>></a></td> </tr> <tr> <th class="wd">Monday</th> <th class="wd">Tuesday</th> <th class="wd">Wednesday</th> <th class="wd">Thursday</th> <th class="wd">Friday</th> <th class="we">Saturday</th> <th class="we">Sunday</th> </tr> <tr> EOT; for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>"; $c = $dow1; for ($d=1; $d<=$dim; $d++, $c++) { if ($c%7==0) echo "</tr><tr>"; $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd'; $st = ($d == $today) ? "style='border: 1pt solid #FF0000'" : ''; echo "<td class=\"$cl\" $st>\n"; /******* * is there an event on this day */ if (isset($events[$d])) echo "<span title='{$events[$d]}' style='font-weight: 600; color: red'>$d</span>"; else echo "$d" ; echo "</td>\n"; } while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>'; echo "</tr></table>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/116059-php-calendar/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.