Jump to content

Recommended Posts

<?php
include "conn.inc.php";

//Checks to see if day, month, and year have been assigned in the url

$day = $_GET["day"];
$month = $_GET["month"];
$year = $_GET["year"];

if ($day == "")
  $day = date("j");
  
if ($month == "")
  $month = date("m");
  
if ($year == "")
  $year = date("Y");
  
  
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
$monthNext = $month + 1;
$monthPrev = $month - 1;

//Fixes monthNext and monthPrev to work with a 12 month calendar

if ($monthNext == 13) {
  $monthNext = 1;
  $yearNext = $year + 1;
} else {
  $yearNext = $year;
}

if ($monthPrev == 0) {
  $monthPrev = 12;
  $yearPrev = $year - 1;
} else {
  $yearPrev = $year;
}


//Turns $EventDate into an array where the array is split up based on the days. For every array the value of 1 is entered to designate
//an event on that day.
$query = "SELECT EventDate FROM CalendarEvents WHERE ((MONTH(EventDate) = " . $month . ") && Validate = 1);";

$result = mysql_query($query, $link)
  or die(mysql_error());

$EventDate = array();

while ($row = mysql_fetch_array($result)) {
  $found = $row['EventDate'];
  $pieces = explode("-", $found);
  $ed = ($pieces[2]);
  
  if ($ed < 10) {
    $ed = intval($ed);
    $EventDate[$ed] = "1";
  } else {
     $EventDate[$ed] = "1";
  }
}

?>

<LINK REL=StyleSheet HREF="calendar.css" TYPE="text/css">

<table width='168' height="17" border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td colspan="7" class="title">
      <font class="title">
      <center>
      <?php 
      echo '<a href="calendar.php?month=' . $monthPrev . '&year=' . $yearPrev . '" class="calendartitle"> << </a>';
      echo $monthName;
      echo '<a href="calendar.php?month=' . $monthNext . '&year=' . $yearNext . '" class="calendartitle"> >> </a>';
      ?>
      </center>
      </font>
    </td>
  </tr>

  <tr class="daylabels">
    <td class='blank' width='24'>Sn</td>
    <td class='blank' width='24'>Mn</td>
    <td class='blank' width='24'>Tu</td>
    <td class='blank' width='24'>Wd</td>
    <td class='blank' width='24'>Th</td>
    <td class='blank' width='24'>Fr</td>
    <td class='blank' width='24'>St</td>
  </tr>
</table>

<table width='168' height="17" border='0' cellspacing='2' cellpadding='0'>
  <tr class="date">
<?php
for ($i = 1; $i < $numDays + 1; $i++, $counter++) {
  $timeStamp = strtotime("$year-$month-$i");

  if ($i == 1) {
//Figures out when the first day of the month is
    $firstDay = date("w",$timeStamp);
//Checks day of the week for first day.
    for($j = 0; $j < $firstDay; $j ++, $counter++)
      echo "<td width='24' height='16' class='blank'> </td>";
  }
  
  if($counter % 7 == 0) {
    echo "</tr><tr class='date'>";
  }
  
  if (($i == date("d") && $month == date("m") && $year == date("Y")) && ($EventDate[$i])) {
    echo "<td width='24' height='16' class='today'><a href='showevent.php?day=$i&month=$month&year=$year' class='calendar' target='_parent'>$i</a></td>";

  } else {
  
  if ($i == date("d") && $month == date("m") && $year == date("Y")){
    echo "<td width='24' height='16' class='today'>$i</td>";

  } else {
  
  if ($EventDate[$i]) {
    echo "<td width='24' height='16' class='event'><a href='showevent.php?day=$i&month=$month&year=$year' class='calendar' target='_parent'>$i</a></td>";

  } else {

  if (date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6) {
    echo "<td width='24' height='16' class='weekend'>$i</td>";
    
  } else {
  
    echo "<td width='24' height='16' class='normal'>$i</td>"; 

  }
  }
  }
  }

}
?>

</table>

 

Check 'er out. I don't really understand why it would be acting this way. To see it in action: http://www.newcovenant-th.org/ and then click the right arrows on the mini-calendar. Something else worth noting . . . it seems to only display as march and with the incorrect amount of days towards the end of the january.

 

Any ideas? As you can see, this is my Church's public website so any help in a timely manner would be GREATLY appreciated.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/88658-solved-february-displays-as-march/
Share on other sites

Anyone?

 

If it helps, I'm pretty sure the problem is in this area:

 

<?php
include "conn.inc.php";

//Checks to see if day, month, and year have been assigned in the url

$day = $_GET["day"];
$month = $_GET["month"];
$year = $_GET["year"];

if ($day == "")
  $day = date("j");
  
if ($month == "")
  $month = date("m");
  
if ($year == "")
  $year = date("Y");
  
  
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
$monthNext = $month + 1;
$monthPrev = $month - 1;

//Fixes monthNext and monthPrev to work with a 12 month calendar

if ($monthNext == 13) {
  $monthNext = 1;
  $yearNext = $year + 1;
} else {
  $yearNext = $year;
}

if ($monthPrev == 0) {
  $monthPrev = 12;
  $yearPrev = $year - 1;
} else {
  $yearPrev = $year;
}

 

and:

<?php 
      echo '<a href="calendar.php?month=' . $monthPrev . '&year=' . $yearPrev . '" class="calendartitle"> << </a>';
      echo $monthName;
      echo '<a href="calendar.php?month=' . $monthNext . '&year=' . $yearNext . '" class="calendartitle"> >> </a>';
      ?>

Try changing this:

 

$currentTimeStamp = strtotime("$year-$month-$day");

 

To this:

 

$currentTimeStamp = mktime(0,0,0,$month,$day,$year);

 

I can't guarantee it will work, but I kind of suspect that your strtotime is causing the troubles. Since no one else is helping, I'm throwing this out as a suggestion, but with no guarantees of success.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.