Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS Issue with PHP Calendar Script.

Status
Not open for further replies.

PaulinKC

Programmer
Apr 2, 2002
50
US
I have a calendar script that when ran, querys a database to see if any events exist, if any do, it should BOLD the font of the date associated with the date entry in the database. The code works, except for bolding of the font. I cannot figure out how to change the bolding of the font. Any ideas?

Below is the code:
Code:
<?php


	//Check if the month and year values exist
	if ((!$_GET['month']) && (!$_GET['year'])) {
		$month = date ("n");
		$year = date ("Y");
		
	} else {
		$month = $_GET['month'];
		$year = $_GET['year'];
	}
	
	if($month==12) { 
		$next=1; 
		$nexty=$year + 1; 
		
	} else { 
		$next=$month + 1; 
		$nexty=$year; 
	}
	
	if($month==1) { 
		$prev=12; 
		$prevy=$year - 1; 
	} else { 
		$prev=$month - 1; 
		$prevy=$year; 
	}
	
	$currentmonth = date("m");
	$currentyear = date("Y");
	
	//Calculate the viewed month
	$timestamp = mktime (0, 0, 0, $month, 1, $year);
	$monthname = date("F", $timestamp);
	$newtable = "<table style=\"width: 225px; border-collapse: collapse;\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\" bordercolor=\"#000000\">
		<tr style=\"background:#68a1d5;color:#ffffff;\">
		<td colspan=\"7\" style=\"text-align: center;\">
			<span style=\"font-weight: bold;\"><a href=javascript:navigateCalendar($prev,$prevy)><img src=\"../images/previousmonth.gif\" alt=\"previous month\" style=\"border:none;\"></a>
			<a href=javascript:navigateCalendar($currentmonth,$currentyear)><img src=\"../images/currentmonth.gif\" alt=\"current month\" style=\"border:none;\"></a>
			 $monthname $year <a href=javascript:navigateCalendar($next,$nexty)><img src=\"../images/nextmonth.gif\" alt=\"next month\" style=\"border:none;\"></a></span>";
	echo $newtable;

	//Now let's create the table with the proper month
	?>

		</td>
		</tr>
		<tr style="background: #0053a0;">
		<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#8bb3d9'" onmouseout="this.style.background='#0053a0'">
			<span style="font-weight: bold;color:#ffffff;">Su</span>
		</td>
		<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#8bb3d9'" onmouseout="this.style.background='#0053a0'">
			<span style="font-weight: bold;color:#ffffff;">M</span>
		</td>
		<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#8bb3d9'" onmouseout="this.style.background='#0053a0'">
			<span style="font-weight: bold;color:#ffffff;">Tu</span>
		</td>
		<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#8bb3d9'" onmouseout="this.style.background='#0053a0'">
			<span style="font-weight: bold;color:#ffffff;">W</span>
		</td>
		<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#8bb3d9'" onmouseout="this.style.background='#0053a0'">
			<span style="font-weight: bold;color:#ffffff;">Th</span>
		</td>
		<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#8bb3d9'" onmouseout="this.style.background='#0053a0'">
			<span style="font-weight: bold;color:#ffffff;">F</span>
		</td>
		<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#8bb3d9'" onmouseout="this.style.background='#0053a0'">
			<span style="font-weight: bold;color:#ffffff;">Sa</span>
		</td>
		</tr>
		<?php				
			$monthstart = date("w", $timestamp);
			//if ($monthstart == 0){
				//$monthstart = 7;
			//}
			$lastday = date("d", mktime (0, 0, 0, $month + 1, 0, $year));
			$startdate = -$monthstart;

			//Let's make 6 rows...
			for ($k = 0; $k < 6; $k++){
				?><tr><?php
				//And 7 columns...
				for ($i = 0; $i < 7; $i++){
					$startdate++;
					if (($startdate <= 0) || ($startdate > $lastday)){
						//If we have a blank day in the calendar.
						?><td style="background: #e0e0e0;">&nbsp;</td><?php
					} else {
																
						if ($startdate == date("j") && $month == date("n") && $year == date("Y")){
							?><td style="text-align: center; background: #68a1d5;" onmouseover="this.style.background='#d1d3d6'" onmouseout="this.style.background='#0053a0'"><?php 
								//Add in the database connector.
								require_once ("dbconnector.php");
								//Open the database.
								$db = opendatabase();
								$querydate = $year . "-" . $month . "-" . $startdate;
								$myquery = "SELECT * FROM localEvents WHERE eventDateStart =" . $querydate;
								$result = mysql_query($myquery);
								$size = mysql_num_rows($result);
								
								if (!$size) {
								
									echo date ("j");
									
								} else {
								
									?><strong><?php echo date("j") ?></strong><?php
								}

								
							?></td><?php
						} else {
							?><td style="text-align: center; background: #A2BAFA;" onmouseover="this.style.background='#d1d3d6'" onmouseout="this.style.background='#A2BAFA'"><?php echo $startdate; ?></td><?php
						}
					}
				}
				?></tr><?php
			}
		?></table>

The problem portion of the code starts at line 103 and continues to line 110. Basically, if the date has any events at all it should bold the date - simple as that. It does display the date but doesn't change the font-weight.

This script is getting called as part of a AJAX app too if that is helpful any.
 
Your problem could have two sources:

1. There's something in your code that makes the strong not work as it should. In that case we can help you, but we need to see client-side code -- whatever the browser sees when it renders the page.

2. There's something in your code that makes the strong not appear in the code. In that case you're having issues with your logic in PHP and you should ask in forum434.

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Run your page, do a "View Source", and see if the <strong> tags are actually appearing where you expect them to. If they are, the fault is probably in your CSS stylesheet (are you using a "reset" style, perhaps?). If the <strong>s are missing, the fault's in your php, probably in the bit where you build the query. Should it, perhaps, be like this?:
Code:
$myquery = "SELECT * FROM localEvents WHERE eventDateStart = '" . $querydate . "'";
Incidentally, it's inefficient to open the connection to the database on each pass of the loop - just open it once at the beginning of the loop and close it at the end.

Anyhoo... that's what I have to say about your problem. Since this is the HTML & CSS forum, I'll say something about your HTML & CSS: it's awfully cumbersome.

For example, you're doing this:
Code:
<tr style="background: #0053a0;">
<td style="text-align: center; width: 15px;" onmouseover="this.style.background='#8bb3d9'" onmouseout="this.style.background='#0053a0'">
<span style="font-weight: bold;color:#ffffff;">Su</span>
</td>
... etc ...
</tr>
That's an awful lot of inline CSS. Why not do this:
Code:
<tr class="daylabels">
  <th>Su</th>
  <th>M</th>
  <th>Tu</th>
  <th>W</th>
  <th>Th</th>
  <th>F</th>
  <th>Sa</th>
</tr>
and add this to your style sheet:
Code:
.daylabels th {
   text-align: center;
   width: 15px;
   background: #0053a0;
   font-weight: bold;
   color:#ffffff;
}

.daylabels th:hover {
   background: #8bb3d9;
}
Isn't that a lot cleaner and easier to maintain?


-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top