Calendar Help? (should be easy)

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Calendar Help? (should be easy)

Post by Jr »

Ok, I'm making a calendar that shows the events for the days in the month view. I'm trying to make it so if one event in the day = $holiday (out of all the events that day) it changes the background color of the day <table> cell.

Below is what I was trying to do...

Code: Select all

<?
$holiday_result = mysql_fetch_array($day_query_1);
while ( $holiday_result[event_type] = "holiday" )
{ $holiday = "true"; }
?>
because every time I do this it makes the day and every day after a different color.

Code: Select all

<?
while ( $holiday_result = mysql_fetch_array($day_query_1) )
{
IF ($holiday_result[event_type] = "holiday")
{ $holiday = "true"; }
}
?>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Code: Select all

<style>
td.normal
{
background-color:#FFFFFF;
}
td.holiday
{
background-color:#123456;
}
</style>
<?while($row = mysql_fetch_assoc($result)){
   $class = "normal";
   if($row['holiday'] == 1)
      $class = "holiday";
   echo "<td class=\"".$class."\">".$row['stuff']."</td>";

}
?>
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

hmm... doesn't seem to be working. Still makes every cell after change colors.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

post your updated code...
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

Ok this is how it looks (I canged it back because it was messing with me with the other parts I was working on). But If you look at about line 51 the backgroundColor change works fine. Can't I just query the DB again before and say IF any_single result = "holiday" make $bg_c = "$something_else" ?

Code: Select all

while ( $day <= $lastday)
	{
		IF ($firstweek)
		{
			//First week row days (that == "")
			echo "<TR height='100px' valign='top'>";
			for ($i=1; $i<=$first_week_day; $i++)
			{
				print "<TD width='$day_wide'>  </td>";
			}
			
			$firstweek = false; 
		}
		
		//Days that have numbers
		IF ($wday==0)
		{
			echo "<tr height='120px' valign='top'>"; 
		} 
		
		// make each day linkable to the following result.php page 
		if ( intval($month_num) < 10)
		{ $new_month_num = "0$month_num"; } 
		elseif (intval($month_num) >= 10)
		{ $new_month_num = $month_num; } 
		
		if ( intval($day) < 10)
		{ $new_day = "0$day"; }
		elseif (intval($day) >= 10)
		{ $new_day = $day; }
		
		$link_date		=	"$year-$new_month_num-$new_day";
		
		$day_query_1	=	mysql_query( "SELECT * FROM calendar WHERE received='$link_date'" );
		$num_rows_1		=	mysql_num_rows($day_query_1); // No LIMIT (Get full qty of rows)
		
		IF ($num_rows_1 > 5)
		{ $limit = 4; } // LIMIT 4 events IF event qty > 5
		ELSE
		{ $limit = 5; } // LIMIT 5 events IF event qty <= 5
		
		$day_query_2	=	mysql_query( "SELECT * FROM calendar WHERE received='$link_date' LIMIT $limit" );
		$num_rows_2		=	mysql_num_rows($day_query_2); // (Only show 4-5 rows)
		
		//Get Holiday
		//$holiday_result = mysql_fetch_array($day_query_1);
		//while ( $holiday_result[event_type] = "holiday" )
		//{ $holiday = "true"; }
		
		// ...and if they match change $day BGColor
		IF ($is_2day == $day && $is_2month == $month_num && $is_2year == $year)
		{ $bg_c = $bgcolour16; }
		
		// Event == "holiday"
		ELSEIF ($holiday == "true")
		{ $bg_c = $bgcolour2; }
		
		// Event != ""
		ELSEIF ($num_rows_2 != 0)
		{ $bg_c = $bgcolour2; }
		
		// Set Default BGColor
		ELSE
		{ $bg_c = $bgcolour7; }
		
		print "<TD bgcolor='$bg_c' width='$day_wide'>";
		
			print "<table width='30px' $border>";
				print "<tr height='26px' onclick=\"location.href='calendar.php?action=events&eventid=$link_date'\">";
					print "<TD bgcolor='$bgcolour10' class='hand_mouse' align='center' onMouseOver=\"this.style.backgroundColor='$bgcolour16';\" onMouseOut=\"this.style.backgroundColor='$bgcolour10';\"><font color='white'><b>$day</b></font></td>";
				print "</tr>";
			print "</table>";
			
			print "<table width='$titlewide' $border>";
				// List events $day cell
				while ( $day_result = mysql_fetch_array($day_query_2) )
				{
					print "<tr>";
						print "<td width='6px'></td>";
						print "<td><font size='1'><li>$day_result[event_type]</li></font></td>";
					print "</tr>";
				}
				// IF events list "num_rows > 5" print link to see "more" entrys for $day
				IF ( $num_rows_1 > 5 )
				{
					print "<tr>";
						print "<td></td>";
						print "<td><li><a href='calendar.php?action=events&eventid=$link_date'><font size='1'>See More...</font></a></li></td>";
					print "</tr>";
				}
			print "</table>";
			
		print "</td>";
		
		if ($wday==6)
		{ 
			echo "</tr>\n"; 
		} 
		
		$wday++; 
		$wday = $wday % 7; 
		$day++; 
	}
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I can only guess that your conditions aren't being met to reset the color back to the default.

if it is the default, why don't you set that at the beginning of the loop, and then change it only if the holiday condition is met?

in other words, but $bg_c = $bgcolour7; at the beginning of the loop, not as your final condition in your if block.
Post Reply