Jump to content

Help with PHP Calendar Display


BleedPinstripes

Recommended Posts

I'm trying to help someone out with their website (which is entirely in PHP) and I've come across a problem I can't seem to figure out.

 

On the site is a php calendar that should display as so:

 

calcorrect.gif

 

However, sometimes for no apparent reason the calendar appears as so:

 

calwrong.gif

 

I cannot seem to determine what is causing this to display incorrectly. It just started happening for no discernible reason.

 

Anyone have any idea where I should start looking to find the issue? It is linked to a MySQL database that is somewhat wonky, could that be the issue?

 

Thanks for any advice you guys can give me.

Link to comment
Share on other sites

It looks like the CSS is screwed up.  For us to be able to help you we would need to see the code.

 

Ken

 

Thanks for any help. Here is the code:

 

 

<div id="cal_right">

<h4>Calendar</h4>

<div id="cal_right_tbl">

 

<?php

// Get the URL.

function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }

$full_url = selfURL();

 

 

// Determine the current Day.

if (isset ($_GET['day'])) {

$day = $_GET['day'];

} else {

$day = date('j');

}

 

// Determine the current Month.

if (isset ($_GET['month'])) {

$month = $_GET['month'];

} else {

$month = date('m');

}

 

// Determine the current Year.

if (isset ($_GET['year'])) {

$year = $_GET['year'];

} else {

$year = date('Y');

}

 

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

$monthName = date("F", $currentTimeStamp);

$numDays = date("t", $currentTimeStamp);

$counter = 1;

$numEventsThisMonth = 0;

$hasEvent = false;

$todaysEvents = "";

?>

 

<table>

 

<caption>

<?php

 

if ($month == 1) {

$previousMonthLink = "day=01&";

$previousMonthLink .= "month=12&";

$previousYear = ($year - 1);

$previousMonthLink .= "year=".$previousYear."";

} else {

$previousMonthLink = "day=01&";

$previousMonth = ($month - 1);

if ($previousMonth <= 9) {

$addZero = 0;

} else {

$addZero = NULL;

}

 

$previousMonthLink .= "month=".$addZero."".$previousMonth."&";

$previousMonthLink .= "year=".$year."";

}

 

if ($month == 12) {

$nextMonthLink = "day=01&";

$nextMonthLink .= "month=01&";

$nextYear = ($year + 1);

$nextMonthLink .= "year=".$nextYear."";

} else {

$nextMonthLink = "day=01&";

$nextMonth = ($month + 1);

if ($nextMonth <= 9) {

$addZero = 0;

} else {

$addZero = NULL;

}

$nextMonthLink .= "month=".$addZero."".$nextMonth."&";

$nextMonthLink .= "year=".$year."";

}

 

if (isset ($_GET['page'])) {

$page = $_GET['page'];

} else {

if (isset ($_GET['action'])) {

$page = $_GET['action'];

} else {

$action = "page/home";

$page = $action;

}

}

echo "<p class=\"cal_arrow_lt\"><a href=\"".$page."&".$previousMonthLink."\">Previous</a></p>";

echo "\n\t\t<h5>".$monthName."";

echo " &#8211; ".$year."</h5>";

echo "\n\t\t<p class=\"cal_arrow_rt\"><a href=\"".$page."&".$nextMonthLink."\">Next</a></p>";

?>

 

</caption>

 

<thead>

<tr>

<th>S</th>

<th>M</th>

<th>T</th>

<th>W</th>

<th>T</th>

<th>F</th>

<th>S</th>

</tr>

</thead>

 

<tbody>

<tr>

<?php

 

$isEvent = FALSE;

 

// Query the database for this months events.

$query = "SELECT * from events WHERE EventYear = $year AND EventMonth= $month";

$result = mysql_query ($query);

 

// Create the array from the database results.

$BigDate = array();

while ($a_row = mysql_fetch_array ($result) ) {

array_push($BigDate, array($a_row["event_date"],$a_row["EventMonth"],$a_row["EventDay"],$a_row["event_id"]));

}

 

for($i = 1; $i < $numDays+1; $i++, $counter++) {

$timeStamp = strtotime("$year-$month-$i");

 

if($i == 1) {

// Workout when the first day of the month is

$firstDay = date("w", $timeStamp);

 

for($j = 0; $j < $firstDay; $j++, $counter++) {

echo "\n\t\t\t<td";

if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6) {

echo " class='weekend'";

}

elseif($i == date("d") && $month == date("m") && $year == date("Y")) {

echo " class='today'";

}

echo "> </td>";

}

}

echo "\n\t\t\t<td";

if(date("w", $timeStamp) == 0 || date("w", $timeStamp) == 6) {

echo " class='weekend'";

}

elseif ($i == date("d") && $month == date("m") && $year == date("Y")) {

echo " class='today'";

}

 

echo ">";

 

// If there is an event, create a link

$eventToday = "".$year."-".$month."-$i";

foreach ($BigDate as $B) {

if (in_array($month, $B)) {

if (in_array ($eventToday, $B)) {

$isEvent = TRUE;

echo "<a href=\"".$root."page/events/calendar&day=".$day."&month=".$month."&year=".$year."&event=".$B['3']."\">";

}

}

}

 

// Display the day of the month.

echo "$i";

 

 

if ($isEvent == TRUE) {

echo "</a>";

}

 

echo"</td>";

if($counter % 7 == 0)

echo "\n\t</tr>\n\t\t<tr>";

}

echo "\n\t\t</tr>";

?>

 

</tbody>

 

</table>

 

<div class="cal_foot">

<?php

if ($isEvent == TRUE) {

$thisMonth = $month;

$thisYear = $year;

echo "View <a href=\"".$root."page/events/calendar&month=".$thisMonth."&year=".$thisYear."\">all events</a> for this month.";

}

?>

</div>

</div>

</div>

Link to comment
Share on other sites

Sorry, I was locating the CSS that pertains to it.

 

 

/* ---------------------------------------------------------------
Calendar Styles
---------------------------------------------------------------- */
#cal_right { width: 200px; }
#cal_right_tbl { padding: 10px 0 0 10px; }
#cal_right table { border-collapse: collapse; }


#cal_right caption { padding: 5px 0 0 10px; border: 1px solid #000; background-color: #ccc; text-align: center; height: 3em; }
#cal_right h5 { font-size: 1.3em; color: #000; float: left; }

p.cal_arrow_lt a { padding-right: 7px; background: url(../images/cal_arrow_lt_on.gif) 2px 2px no-repeat; text-indent: -9999px;  width: 18px; height: 17px; float: left; display: block; }
p.cal_arrow_lt a:link, p.cal_arrow_lt a:visited { background: url(../images/cal_arrow_lt_off.gif) 2px 2px no-repeat; }
p.cal_arrow_lt a:hover { background: url(../images/cal_arrow_lt_on.gif) 2px 2px no-repeat; }

p.cal_arrow_rt a { padding-left: 7px; background: url(../images/cal_arrow_rt_on.gif) 2px 2px no-repeat; text-indent: -9999px;  width: 18px; height: 17px; float: left; display: block; }
p.cal_arrow_rt a:link, p.cal_arrow_rt a:visited { background: url(../images/cal_arrow_rt_off.gif) 2px 2px no-repeat; }
p.cal_arrow_rt a:hover, p.cal_arrow_rt a:focus { background: url(../images/cal_arrow_rt_on.gif) 2px 2px no-repeat; }


#cal_right thead { background-color: #000; color: #fff; }
#cal_right td, #cal_right th { text-align: center; width: 27px; }

#cal_right table td.today { background: #ccc; }
#cal_right a:link { color: #000; text-decoration: underline; }
#cal_right a:visited { color: #333; text-decoration: underline; }
#cal_right a:hover, #cal_right a:focus { color: #9d1c33; text-decoration: none; }

.cal_foot { padding-left: 13px; margin: 5px 0 0 2px; background: url(../images/cal_foot.gif) 0 5px no-repeat; }

Link to comment
Share on other sites

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.