PHP/CSS calendar - glitch with specific days

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
wabbitt
Forum Newbie
Posts: 2
Joined: Thu Mar 08, 2012 3:34 pm

PHP/CSS calendar - glitch with specific days

Post by wabbitt »

Hi, all:

I'm new to this forum and I need some help troubleshooting an issue in a custom PHP/CSS-driven calendar I've created for one of the websites I maintain. I've been using and experimenting with PHP in my work for several years, mostly with regards to file includes and date functions, etc. This is probably my most ambitious project yet. All was working well, and the client has already previewed my work and we are going to be publishing calendar soon. Today, however, I noticed that the code which highlights the current day in the calendar (by changing the CSS background and text colour) works fine for every day except today -- the 8th -- and the 9th. I've checked and rechecked my code. It's the same in all my calendar months, always with the 8th and the 9th day, but none of the others. I'm stumped. I've stripped things down to the month of March in a single PHP file with the basic necessary scripting for troubleshooting, which I'm including below. Any thoughts/suggestions about why the glitch with the 8th and 9th? I can post screen shots to better illustrate the desired result, if necessary. Thanks! 'Wabbittt'

Code: Select all

<?php 
function setColor($calDay,$calMon,$eventExists) 
{

$thisDay = date('d');
$thisMonth = date('m');

// d = Day of the month, 2 digits with leading zeros
// j = Day of the month without leading zeros
// m = Numeric representation of a month, with leading zeros
// n = Numeric representation of a month, without leading zeros

// Script to highlight current day in calendar.

if ($calDay == $thisDay && $calMon == $thisMonth)  	// if day is current day and month is current month...
	{
	$dayColor = "background-color: #9cf; color: #fff; font-weight: bold;";
	} 
elseif ($calDay == $thisDay && $calMon == $thisMonth && $eventExists == "y")  	// if day is current day and has events...
	{
	$dayColor = "background-color: #9cf;";
	}
elseif ($eventExists == "y" && $calDay != $thisDay) 	// if day is not current day and has events...
	{
	$dayColor = "background-color: #def; color: #000;";
	}
else 		// if day is not current day and has no events...
	{
	$dayColor = "background-color: #fff; color: #000;";
	}
echo $dayColor;
}
?>

<h2 style="text-align: center;">March 2012</h2>

<table class="calendar" width="100%" cellpadding="0" cellspacing="0" border="1">
  <tr>
    <th>SUN</th><th>MON</th><th>TUE</th><th>WED</th><th>THU</th><th>FRI</th><th>SAT</th>
  </tr>
  <tr>
    <td class="noDay">&nbsp;</td>
    <td class="noDay">&nbsp;</td>
    <td class="noDay">&nbsp;</td>
    <td class="noDay">&nbsp;</td>
    <td id="01" style="<?php setColor(01,03,n);?>">1</td>
    <td id="02" style="<?php setColor(02,03,y);?>"><a href="#">2</a></td>
    <td id="03" style="<?php setColor(03,03,n);?>">3</td>
  </tr>
  <tr>
    <td id="04" style="<?php setColor(04,03,n);?>">4</td>
    <td id="05" style="<?php setColor(05,03,y);?>"><a href="#">5</a></td>
    <td id="06" style="<?php setColor(06,03,n);?>">6</td>
    <td id="07" style="<?php setColor(07,03,n);?>">7</td>
    <td id="08" style="<?php setColor(08,03,n);?>">8</td>
    <td id="09" style="<?php setColor(09,03,y);?>"><a href="#">9</a></td>
    <td id="10" style="<?php setColor(10,03,n);?>">10</td>
  </tr>
  <tr>
    <td id="11" style="<?php setColor(11,03,n);?>">11</td>
    <td id="12" style="<?php setColor(12,03,n);?>">12</td>
    <td id="13" style="<?php setColor(13,03,n);?>">13</td>
    <td id="14" style="<?php setColor(14,03,n);?>">14</td>
    <td id="15" style="<?php setColor(15,03,n);?>">15</td>
    <td id="16" style="<?php setColor(16,03,n);?>">16</td>
    <td id="17" style="<?php setColor(17,03,n);?>">17</td>
  </tr>
  <tr>
    <td id="18" style="<?php setColor(18,03,n);?>">18</td>
    <td id="19" style="<?php setColor(19,03,y);?>"><a href="#">19</a></td>
    <td id="20" style="<?php setColor(20,03,y);?>"><a href="#">20</a></td>
    <td id="21" style="<?php setColor(21,03,n);?>">21</td>
    <td id="22" style="<?php setColor(22,03,n);?>">22</td>
    <td id="23" style="<?php setColor(23,03,n);?>">23</td>
    <td id="24" style="<?php setColor(24,03,n);?>">24</td>
  </tr>
  <tr>
    <td id="25" style="<?php setColor(25,03,n);?>">25</td>
    <td id="26" style="<?php setColor(26,03,n);?>">26</td>
    <td id="27" style="<?php setColor(27,03,n);?>">27</td>
    <td id="28" style="<?php setColor(28,03,n);?>">28</td>
    <td id="29" style="<?php setColor(29,03,n);?>">29</td>
    <td id="30" style="<?php setColor(30,03,n);?>">30</td>
    <td id="31" style="<?php setColor(31,03,n);?>">31</td>
  </tr>
</table>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP/CSS calendar - glitch with specific days

Post by Celauran »

Pass your arguments as strings and everything works as intended.

Code: Select all

setColor('08', '03', 'n');
wabbitt
Forum Newbie
Posts: 2
Joined: Thu Mar 08, 2012 3:34 pm

Re: PHP/CSS calendar - glitch with specific days

Post by wabbitt »

Celauran wrote:Pass your arguments as strings and everything works as intended.

Code: Select all

setColor('08', '03', 'n');
That was exactly it, and in front of me the whole time. Thank you, Celauran! :)
Post Reply