Build A Calender

Started on the old forum in May 2008 · view the original in the archive · old links redirect here

10 replies · 979 views · started 18 years ago · 1 min read

7 participants
rukiya Lead · 569 posts #1

Here is a code to make calender

<?php
  $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
    if (!isset($_REQUEST["year"]))  $_REQUEST["year"]  = date("Y");
    
  $cMonth = $_REQUEST["month"];
  $cYear  = $_REQUEST["year"];
                
  $prev_year = $cYear;
  $next_year = $cYear;

     $prev_month = $cMonth-1;
     $next_month = $cMonth+1;

     if ($prev_month == 0 ) {
    $prev_month = 12;
    $prev_year = $cYear - 1;
  }
     if ($next_month == 13 ) {
    $next_month = 1;
    $next_year = $cYear + 1;
  }
?>
   <div id="calendar_div" name="calendar_div">
    <table width="200">
        <tr align="center">
          <td bgcolor="#999999" style="color:#FFFFFF">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="50%" align="left">[url="<?php echo $_SERVER["]" style="color:#FFFFFF">Previous[/url]</td>
                      <td width="50%" align="right">[url="<?php echo $_SERVER["]" style="color:#FFFFFF">Next[/url]</td>
                    </tr>
              </table>
          </td>
        </tr>
        <tr>
            <td align="center">
              <table width="100%" border="0" cellpadding="2" cellspacing="2">
                <tr align="center">
                  <td colspan="7" bgcolor="#999999" style="color:#FFFFFF">[b]<?php echo $monthNames[$cMonth-1].' '.$cYear; ?>[/b]</td>
                </tr>
                <tr>
                  <td align="center" bgcolor="#999999" style="color:#FFFFFF">[b]S[/b]</td>
                  <td align="center" bgcolor="#999999" style="color:#FFFFFF">[b]M[/b]</td>
                  <td align="center" bgcolor="#999999" style="color:#FFFFFF">[b]T[/b]</td>
                  <td align="center" bgcolor="#999999" style="color:#FFFFFF">[b]W[/b]</td>
                  <td align="center" bgcolor="#999999" style="color:#FFFFFF">[b]T[/b]</td>
                  <td align="center" bgcolor="#999999" style="color:#FFFFFF">[b]F[/b]</td>
                  <td align="center" bgcolor="#999999" style="color:#FFFFFF">[b]S[/b]</td>
                </tr>

                <?php 
                    $timestamp = mktime(0,0,0,$cMonth,1,$cYear);
                    $maxday    = date("t",$timestamp);
                    $thismonth = getdate ($timestamp);
                    $startday  = $thismonth['wday'];

                  for ($i=0; $i<($maxday+$startday); $i++) {
                    if(($i % 7) == 0 ) echo "<tr>\n";
                    if($i < $startday) echo "<td></td>\n";
                    else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td>\n";
                    if(($i % 7) == 6 ) echo "</tr>\n";
                  }  
                 ?>
              </table>
            </td>
        </tr>
    </table>
</div>
darkdesire Senior · 250 posts #2

nice thank you, much better than the one i had

:p:p:p

immortalempire Developer · 219 posts #3

thats good got a question though , what will happen in 2009 does it automatically change

immortalempire Developer · 219 posts #5

you would not ask it if you knew the meaning of

 if (!isset($_REQUEST["year"]))  $_REQUEST["year"]  = date("Y");

i dont know the meaning so why you think i was asking lol some ppl eh

kaibaspoon Developer · 63 posts #10

Mmmmmm i dont get it what dos this do.......do i put it in a page or in a seperate page lol

Just kidding...

WhiteWarrior Principal · 1,419 posts #11

This should of gone in Source codes, small scripts... topic... never mind... closed

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close