PHP calendar

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lubber123
Forum Commoner
Posts: 51
Joined: Mon Sep 15, 2008 12:26 pm
Location: Manassas, VA

PHP calendar

Post by lubber123 »

I am having an issue with a php calendar I am attempting to put up. The structure works fine but when I do my query and insert data from the Db it places it outside the cells and generally creates a mess.

Can anyone familiar with this help?

Here is a url to the test page: http://www.lfmi.org/staff/admin2.php

Here is my calendar code:

Code: Select all

 
//CALENDAR
  $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="100%" bgcolor="#FFCC66" border="1" bordercolor="#003366">
                                  <tr align="center">
                                    <td bgcolor="#999999" style="color:#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                          <td width="50%" align="left">&nbsp;&nbsp;<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
                                          <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a>&nbsp;&nbsp;</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" height="40" valign="middle"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
                                        </tr>
                                        <tr>
                                          <td align="left" bgcolor="#999999" style="color:#FFFFFF" height="25" valign="middle"><strong>Sunday</strong></td>
                                          <td align="left" bgcolor="#999999" style="color:#FFFFFF" height="25" valign="middle"><strong>Monday</strong></td>
                                          <td align="left" bgcolor="#999999" style="color:#FFFFFF" height="25" valign="middle"><strong>Tuesday</strong></td>
                                          <td align="left" bgcolor="#999999" style="color:#FFFFFF" height="25" valign="middle"><strong>Wednesday</strong></td>
                                          <td align="left" bgcolor="#999999" style="color:#FFFFFF" height="25" valign="middle"><strong>Thursday</strong></td>
                                          <td align="left" bgcolor="#999999" style="color:#FFFFFF" height="25" valign="middle"><strong>Friday</strong></td>
                                          <td align="left" bgcolor="#999999" style="color:#FFFFFF" height="25" valign="middle"><strong>Saturday</strong></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";
                            //QUERYING THE DB FOR THE EVENTS IN THE DATE RANGE
                            $todate = $cYear . "-" . $cMonth . "-" . ($i - $startday + 1);
                            echo $query = "SELECT id, event_name, event_date, event_date_end, day FROM event_checklists WHERE event_date >= '" . $todate . "' && event_date_end >= '" . $todate . "' Order by event_name";
                            $result = mysql_query($query, $connection) or die(mysql_error());
                    if($i < $startday) echo "<td></td>\n";
                    
                    else echo "<td align='left'; style='bgcolor='#FFCC66'; height='200'; border='1'; bordercolor='#003366';'>" . ($i - $startday + 1); 
                                 while($row = mysql_fetch_array($result)){
                                    echo $row['event_name'] . "<br />";
                                }
                        echo "</td>\n";
                         
                    if(($i % 7) == 6 ) echo "</tr>\n";
                  }  
                 ?>
 
Thank you.
ramblin54321
Forum Commoner
Posts: 32
Joined: Wed Nov 18, 2009 5:31 am

Re: PHP calendar

Post by ramblin54321 »

I recommend taking out all size dimensions such as your td 50% and your height = 40 etc. and replace with cascading style sheet dimensions in pixels e.g., width:400px; or position relative left 24 px; You will need to play with it until it is right and check it on different sized browsers.
Post Reply