Calgaryalberta Posted May 27, 2008 Share Posted May 27, 2008 I have a calendar installed on my website, the way it currently works is you hover your mouse over a data and all the events for that date appear. What I would like it to do is allow someone to click on the date, and the information for that date appears in a pop-up window. Now Im not sure how to do this. Is it possible to make pop-up windows in php, or do I have to embed some sort of java-script within the php scripting, or how would that work, my code is below if anyone would like to take a look at it. <?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/107466-help-or-recommendation/ Share on other sites More sharing options...
ILYAS415 Posted May 27, 2008 Share Posted May 27, 2008 Hehe lol. Quite simple actually. Okay first create a page. something like popup.php Now go back to your original calendar page, and and this hyperlink to the date text things on the calendar... <a href="popUp('popup.php?date=datevariablehereinphp')">date var here</a> then somewhere near the top of the page add this code... <script language="JavaScript"> <!-- Idea by: Nic Wolfe --> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <!-- Begin function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500,left = 262,top = 134');"); } // End --> </script> Code is from http://javascript.internet.com/generators/popup-window.html On your popup.php page you need to try to get a $_GET['date'] thing, process it and then etc etc show some information and events. Hope it helped. P.s. codes may need a little tweaking and im not sure if the link example willl work hundred percent. Link to comment https://forums.phpfreaks.com/topic/107466-help-or-recommendation/#findComment-550859 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.