pgsjoe Posted March 13, 2006 Share Posted March 13, 2006 First off, I did the smart thing and searched Forums found some info but the other calendar systems didn't do exactly what I needed and figured I'm already halfway there so I'd just continue trying to work on mine, but I hit a brick wall and can't get anymore to work. So...if anybody has the time to figure this out, I would appreciate it.I can get all the info entered into the database and even to display correctly with all of the information I need. That was the easy part.. So now, I searched around and found a script that generates a whole month numerically (http://keithdevens.com/software/php_calendar).In describing the list he talks about setting up the days to show as links to specific events. He just lists them as links, but there has to be a way to automate this from my database, right? So that if there is an event on a specific day, I could make it a link to that event's information?Here's the page I'm working on: [a href=\"http://www.asse.org/calendar/index3.php\" target=\"_blank\"]http://www.asse.org/calendar/index3.php[/a]I'm also having quite the problem with arrows to go back and forth between month. I can get it to go one month in either direction but then it stops there. Here's the code for the month stuff....[code]$next = $_SERVER['PHP_SELF'] . '?addmonth=1';$last = $_SERVER['PHP_SELF'] . '?submonth=1'; if (isset($_GET['addmonth'])) { $time = mktime(0, 0, 0, date("m")+1, date("d"), date("Y")); } else if (isset($_GET['submonth'])) { $time = mktime(0, 0, 0, date("m")-3, date("d"), date("Y")); } else { $time = time(); } $today = date('j',$time);$month = date('m',$time);$year = date('Y',$time);$days = array($today=>array(NULL,NULL,'<span class="currentday">'.$today.'</span>'));$pn = array('«'=>$last, '»'=>$next); echo '<div id="side">';echo generate_calendar(date('Y', $time), $month, $days, 0, NULL, 0, $pn);echo '<center> <p class="addevent"><a href="' . $_SERVER['PHP_SELF'] . '?addevent=1">Add Event</a></p> </center></div>'; // Request all events $result = @mysql_query("SELECT * FROM `calendar` WHERE date LIKE '%-$month-%' AND date LIKE '$year%' GROUP BY date ASC, id ASC"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); }[/code]As for the days being links, the code I got from it says to still use the generate_calendar function above and use this...[code] $days = array( 2=>array('/weblog/archive/2004/Jan/02','linked-day'), 3=>array('/weblog/archive/2004/Jan/03','linked-day'), 8=>array('/weblog/archive/2004/Jan/08','linked-day'), 22=>array('/weblog/archive/2004/Jan/22','linked-day'), 26=>array(NULL,'linked-day textual','twenty-six'), ); [/code]but how would I get that to automatically pull events from my table. I know it'd have to be a SQL statement such as..SELECT * FROM `calendar` WHERE date LIKE '%-$month-%' AND date LIKE '$year%'Any help is greatly appreciated. I've been struggling with this all last week and am really looking for some answers.- JoE - Quote Link to comment https://forums.phpfreaks.com/topic/4857-building-a-php-calendar/ Share on other sites More sharing options...
hitman6003 Posted March 14, 2006 Share Posted March 14, 2006 Here's a calender I did a while back...hope it helps:[code]<?php$months = array('January' => 1, 'February' => 2, 'March' => 3, 'April' => 4, 'May' => 5, 'June' => 6, 'July' => 7, 'August' => 8, 'September' => 9, 'October' => 10, 'November' => 11, 'December' => 12 ); $days = array( 'Sunday' => 0, 'Monday' => 1, 'Tuesday' => 2, 'Wednesday' => 3, 'Thursday' => 4, 'Friday' => 5, 'Saturday' => 6,);//month to display calender for$m = $_GET['m'];if ($m == "") { $m = mktime(NULL, NULL, NULL, date('m'), 1, date('Y'));}//echo date('Y-m-d H:i:s', $m);$month = date("m", $m);$year = date("Y", $m);$prevmonth = mktime(NULL, NULL, NULL, $month-1, 1, $year);$prevyear = mktime(NULL, NULL, NULL, $month, 1, $year-1);$nextmonth = mktime(NULL, NULL, NULL, $month+1, 1, $year);$nextyear = mktime(NULL, NULL, NULL, $month, 1, $year+1);//determine the starting day for the first//$fd = mktime(NULL, NULL, NULL, $m, 1, $y);$firstday = date('l', $m);$daysinmonth = date('t', $m);$startday = $days[$firstday];$day = 1;$today = mktime(NULL, NULL, NULL, date('m'), date('d'), date('Y'));$thismonth = date('m');//echo date("Y-m-d", '1130821200');function dayhtml($day) { global $today, $month, $year, $conn; $blah = mktime(NULL, NULL, NULL, $month, $day, $year); //$disp = '<a href="daydetail.php?m=' . mktime(NULL, NULL, NULL, $month, $day, $year) . '">' . $day . '</a> '; $disp = $day; if ($blah == $today) { return '<td width="14%" style="background-color: #66CCDD;" onmouseover="this.style.backgroundColor=\'#66AACC\';" onmouseout="this.style.backgroundColor=\'#66CCDD\';">' . $disp . '<br>' . $inner . '</td>'; } else { return '<td width="14%" onmouseover="this.style.backgroundColor=\'#66AACC\';" onmouseout="this.style.backgroundColor=\'white\';">' . $disp . '<br>' . $inner . '</td>'; }}function emptyday() { return '<td width="14%"> </td>';}$firstweek = "";for ($i = 0; $i < $startday; $i++) { $firstweek .= emptyday();}for ($i = $startday; $i <= 6; $i++) { $firstweek .= dayhtml($day); $day++;}$secondweek = "";for ($i = 0; $i <= 6; $i++) { if ($day <= $daysinmonth) { $secondweek .= dayhtml($day); } else { $secondweek .= emptyday(); } $day++;}$thirdweek = "";for ($i = 0; $i <= 6; $i++) { if ($day <= $daysinmonth) { $thirdweek .= dayhtml($day); } else { $thirdweek .= emptyday(); } $day++;}$fourthweek = "";for ($i = 0; $i <= 6; $i++) { if ($day <= $daysinmonth) { $fourthweek .= dayhtml($day); } else { $fourthweek .= emptyday(); } $day++;}$fifthweek = "";if ($day <= $daysinmonth) { $fifthweek = "<tr valign=\"top\" height=\"100\">"; for ($i = 0; $i <= 6; $i++) { if ($day <= $daysinmonth) { $fifthweek .= dayhtml($day); } else { $fifthweek .= emptyday(); } $day++; } $fifthweek .= "</tr>";}$sixthweek = "";if ($day <= $daysinmonth) { $sixthweek = "<tr valign=\"top\" height=\"100\">"; for ($i = 0; $i <= 6; $i++) { if ($day <= $daysinmonth) { $sixthweek .= dayhtml($day); } else { $sixthweek .= emptyday(); } $day++; } $sixthweek .= "</tr>";}?><html><head></head><body><style>td { border: 1px solid lightblue; font-size: .6em;}</style><table border="0" cellspacing="2" cellpadding="2" width="100%" style="border: 1px solid lightblue"> <tr> <th align="left"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?php echo $prevmonth ?>" alt="Previous Month"><</a> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?php echo $prevyear ?>" alt="Previous Year"><<</a></th> <th colspan="5" align="center" id="ignore"><h2><?php echo date('F', $m); ?> <?php echo date('Y', $m); ?></h2></th> <th align="right"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?php echo $nextyear ?>" alt="Next Year">>></a> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?php echo $nextmonth ?>" alt="Next Month">></a></th> </tr> <tr> <th>Sunday</th> <th>Monday</th> <th>Tuesday</th> <th>Wednesday</th> <th>Thursday</th> <th>Friday</th> <th>Saturday</th> </tr> <tr height="100" valign="top" > <?php echo $firstweek; ?> </tr> <tr height="100" valign="top" > <?php echo $secondweek; ?> </tr> <tr height="100" valign="top" > <?php echo $thirdweek; ?> </tr> <tr height="100" valign="top" > <?php echo $fourthweek; ?> </tr> <?php echo $fifthweek; ?> <?php echo $sixthweek; ?></table></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4857-building-a-php-calendar/#findComment-17192 Share on other sites More sharing options...
pgsjoe Posted March 14, 2006 Author Share Posted March 14, 2006 YES! This worked awesome for changing between months. Last gap I need to fill in is automating the days to fill in the calendar as links from the database. Help just a bit more please?- JoE - Quote Link to comment https://forums.phpfreaks.com/topic/4857-building-a-php-calendar/#findComment-17237 Share on other sites More sharing options...
pgsjoe Posted March 14, 2006 Author Share Posted March 14, 2006 thought it was working...turns out it won't go back to the previous year though. When you go to the month before January, it's only changing the month, and not the year. Here's what I'm pulling....[code]//month to display calender for$m = $_GET['m'];if ($m == "") { $m = mktime(NULL, NULL, NULL, date('m'), 1, date('Y'));}$month = date("m", $m);//$year = date("Y", $m);$prevmonth = mktime(NULL, NULL, NULL, $month-1, 1, date('Y'));$nextmonth = mktime(NULL, NULL, NULL, $month+1, 1, date('Y'));$today = mktime(NULL, NULL, NULL, date('m'), date('d'), date('Y'));$thismonth = date('m');$time = $today;$backmonth = $_SERVER['PHP_SELF'] . '?m=' . $prevmonth;$forwardmonth = $_SERVER['PHP_SELF'] . '?m=' . $nextmonth; $days = array($today=>array(NULL,NULL,'<span class="currentday">'.$today.'</span>'));$pn = array('«'=>$backmonth, '»'=>$forwardmonth); echo '<div id="side">';echo generate_calendar(date('Y', $time), $month, $days, 0, NULL, 0, $pn);echo '<center> <p class="addevent"><a href="' . $_SERVER['PHP_SELF'] . '?addevent=1">Add Event</a></p> </center></div>'; // Request all events $result = @mysql_query("SELECT * FROM `calendar` WHERE date LIKE '%-$month-%' AND date LIKE '$year%' GROUP BY date ASC, id ASC"); if (!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); }[/code]Alright...I'll probably have more questions after this, but at least I'll never ask the same question twice.- JoE - Quote Link to comment https://forums.phpfreaks.com/topic/4857-building-a-php-calendar/#findComment-17260 Share on other sites More sharing options...
pgsjoe Posted March 14, 2006 Author Share Posted March 14, 2006 Got it to work between the months/years....I missed one piece when integrating the code into mine. Just need to figure out the days array. Quote Link to comment https://forums.phpfreaks.com/topic/4857-building-a-php-calendar/#findComment-17380 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.