ChompGator Posted April 20, 2008 Share Posted April 20, 2008 Hey Everyone, I started coding my calendar, and right now it is just showing April...What I want to do is this `<< April >>` And the arrows will control the month - Adding the arrows are simple, basic html, but how do I get it so when the arrows are clicked they go to the next or previous month and show the correct days for that month. I haven't attempted it yet...I wanted to get some input before I go further, any help is great, Im going to read some more on google too - here is the code so far: <?php // get this month and this years as an int $thismonth = ( int ) date( "m" ); $thisyear = date( "Y" ); // Number of Days $numdaysinmonth = cal_days_in_month( CAL_GREGORIAN, $thismonth, $thisyear ); // Calendar object $jd = cal_to_jd( CAL_GREGORIAN, date( "m" ),date( 1 ), date( "Y" ) ); // get the start day as an int (0 = Sunday, 1 = Monday, etc) $startday = jddayofweek( $jd , 0 ); // get the month as a name $monthname = jdmonthname( $jd, 1 ) ?><center> <table> <tr> <td colspan="7"><div align="center"><strong><?= $monthname ?></strong></div></td> </tr> <tr> <td><strong>S</strong></td> <td><strong>M</strong></td> <td><strong>T</strong></td> <td><strong>W</strong></td> <td><strong>T</strong></td> <td><strong>F</strong></td> <td><strong>S</strong></td> </tr> <tr></center> <?php // put render empty cells $emptycells = 0; for( $counter = 0; $counter < $startday; $counter ++ ) { echo "\t\t<td>-</td>\n"; $emptycells ++; } // renders the days $rowcounter = $emptycells; $numinrow = 7; for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ ) { $rowcounter ++; echo "\t\t<td>$counter</td>\n"; if( $rowcounter % $numinrow == 0 ) { echo "\t</tr>\n"; if( $counter < $numdaysinmonth ) { echo "\t<tr>\n"; } $rowcounter = 0; } } // clean up $numcellsleft = $numinrow - $rowcounter; if( $numcellsleft != $numinrow ) { for( $counter = 0; $counter < $numcellsleft; $counter ++ ) { echo "\t\t<td>-</td>\n"; $emptycells ++; } } ?> </tr> </table> </body> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Barand Posted April 20, 2008 Share Posted April 20, 2008 try <?php $month = isset($_GET['month']) ? $_GET['month'] : date('n'); $year = isset($_GET['year']) ? $_GET['year'] : date('Y'); $monthname = date('F', mktime (0,0,0,$month,1,$year)); $prevM = $month==1 ? 12 : $month-1; $prevY = $month==1 ? $year - 1 : $year; $nextM = $month==12 ? 1 : $month+1; $nextY = $month==12 ? $year + 1 : $year; echo "<a href='?month=$prevM&year=$prevY'><<</a> $monthname $year <a href='?month=$nextM&year=$nextY'>>></a>"; ?> Quote Link to comment Share on other sites More sharing options...
ChompGator Posted April 20, 2008 Author Share Posted April 20, 2008 This works well Problem is - it shows the month allows scrolling back and fourth but doesn't show any calendar lol! I tried in-corporating it with my script above, but it hasn't worked yet, Im going to play with it some more, any suggestions let me know Quote Link to comment Share on other sites More sharing options...
ChompGator Posted April 20, 2008 Author Share Posted April 20, 2008 Here is what the script looks like now: Its not showing the calendar but its allowing me to scroll back and fourth between months. <?php $month = isset($_GET['month']) ? $_GET['month'] : date('n'); $year = isset($_GET['year']) ? $_GET['year'] : date('Y'); $monthname = date('F', mktime (0,0,0,$month,1,$year)); $prevM = $month==1 ? 12 : $month-1; $prevY = $month==1 ? $year - 1 : $year; $nextM = $month==12 ? 1 : $month+1; $nextY = $month==12 ? $year + 1 : $year; echo "<a href='?month=$prevM&year=$prevY'><<</a> $monthname $year <a href='?month=$nextM&year=$nextY'>>></a>"; ?><center> <table> <tr> <td colspan="7"><div align="center"><strong><?= $monthname ?></strong></div></td> </tr> <tr> <td><strong>S</strong></td> <td><strong>M</strong></td> <td><strong>T</strong></td> <td><strong>W</strong></td> <td><strong>T</strong></td> <td><strong>F</strong></td> <td><strong>S</strong></td> </tr> <tr></center> <?php // put render empty cells $emptycells = 0; for( $counter = 0; $counter < $startday; $counter ++ ) { echo "\t\t<td>-</td>\n"; $emptycells ++; } // renders the days $rowcounter = $emptycells; $numinrow = 7; for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ ) { $rowcounter ++; echo "\t\t<td>$counter</td>\n"; if( $rowcounter % $numinrow == 0 ) { echo "\t</tr>\n"; if( $counter < $numdaysinmonth ) { echo "\t<tr>\n"; } $rowcounter = 0; } } // clean up $numcellsleft = $numinrow - $rowcounter; if( $numcellsleft != $numinrow ) { for( $counter = 0; $counter < $numcellsleft; $counter ++ ) { echo "\t\t<td>-</td>\n"; $emptycells ++; } } ?> </tr> </table> </body> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Barand Posted April 20, 2008 Share Posted April 20, 2008 I thought that's what you wanted. You appeared to have code for the calendar Quote Link to comment Share on other sites More sharing options...
ChompGator Posted April 20, 2008 Author Share Posted April 20, 2008 Yep, no thats excatly what I wanted...Its just that its letting me scroll back and fourth between months, but its not changing the calendar dates. (Ill send you a pvt with the URL you can go to, to take a look at it) Current Code: <?php $month = isset($_GET['month']) ? $_GET['month'] : date('n'); $year = isset($_GET['year']) ? $_GET['year'] : date('Y'); $monthname = date('F', mktime (0,0,0,$month,1,$year)); $prevM = $month==1 ? 12 : $month-1; $prevY = $month==1 ? $year - 1 : $year; $nextM = $month==12 ? 1 : $month+1; $nextY = $month==12 ? $year + 1 : $year; echo "<a href='?month=$prevM&year=$prevY'><<</a> $monthname $year <a href='?month=$nextM&year=$nextY'>>></a>"; ?><center> <table> <tr> <td colspan="7"><div align="center"><strong><?= $monthname ?></strong></div></td> </tr> <tr> <td><strong>S</strong></td> <td><strong>M</strong></td> <td><strong>T</strong></td> <td><strong>W</strong></td> <td><strong>T</strong></td> <td><strong>F</strong></td> <td><strong>S</strong></td> </tr> <tr></center> <?php // put render empty cells $emptycells = 0; for( $counter = 0; $counter < $startday; $counter ++ ) { echo "\t\t<td>-</td>\n"; $emptycells ++; } // renders the days $rowcounter = $emptycells; $numinrow = 7; for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ ) { $rowcounter ++; echo "\t\t<td>$counter</td>\n"; if( $rowcounter % $numinrow == 0 ) { echo "\t</tr>\n"; if( $counter < $numdaysinmonth ) { echo "\t<tr>\n"; } $rowcounter = 0; } } // clean up $numcellsleft = $numinrow - $rowcounter; if( $numcellsleft != $numinrow ) { for( $counter = 0; $counter < $numcellsleft; $counter ++ ) { echo "\t\t<td>-</td>\n"; $emptycells ++; } } ?> </tr> </table> </body> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Barand Posted April 20, 2008 Share Posted April 20, 2008 Here's one I wrote about 3 years ago <html> <!-- Creation date: 04/02/05 --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>baaCalendar</title> <meta name="Author" content="Barand"> <meta name="Generator" content="AceHTML 4 Pro"> <style type="text/css"> TD {font-family: arial; font-size: 9pt; text-align: center; height: 20} TH {font-family: arial; font-size: 9pt; text-align: center; width: 20px; height: 20; font-weight: 600; color: #FFFFFF} TH.wd {background: #99CC99} TH.we {background: #999999} TD.we {background: #EEEEEE; } TD.wd {background: #EEFFEE} TD.hd {background: #FFFFFF; color: #339900} A.nul {text-decoration: none} A:hover {background: #DDDDDD; color: #FF0000} </style> </head> <body> <?php $currMonth = isset($_GET['month']) ? $_GET['month'] : date('n'); $currYear = isset($_GET['year']) ? $_GET['year'] : date('Y'); $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">M</th> <th class="wd">T</th> <th class="wd">W</th> <th class="wd">T</th> <th class="wd">F</th> <th class="we">S</th> <th class="we">S</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"; echo "$d" ; echo "</td>\n"; } while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>'; echo "</tr></table>\n"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
ChompGator Posted April 20, 2008 Author Share Posted April 20, 2008 Hey man, That is fantastic! Thanks a bunch for that! Funny thing, I just got mine too work before you posted yours, but yours looks more stylish hah, so Im going to use it! ...Now what Im going to try and do is make it > so when you hover over a number on the calendar > a little window to left-side of the mouse arrow will appear > and display what event is on that day! Should be more of a challenge! First I have to make an area where users can post an event and that information goes into the database > then in the window that appears Im just going to get it to call whatever event is on that day from the database and display it in the little window that appears...when you hover your mouse over a certain date. Im sure Ill have trouble with that too, but Im going to start coding! Anyway thanks again! Quote Link to comment Share on other sites More sharing options...
ChompGator Posted April 20, 2008 Author Share Posted April 20, 2008 Problem is, Its only showing 2000, but I think I can fix that. take it easy. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 20, 2008 Share Posted April 20, 2008 It was working when it left the shop Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 20, 2008 Share Posted April 20, 2008 It was working when it left the shop A true salesman. Quote Link to comment Share on other sites More sharing options...
ChompGator Posted April 20, 2008 Author Share Posted April 20, 2008 It was working when it left the shop A true salesman. Is that the truth haha! Quote Link to comment 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.