2 Replies - 929 Views - Last Post: 14 August 2009 - 05:54 AM Rate Topic: -----

#1 DCMark  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-July 09

Start and End dates? Fill in the dates in between?

Post icon  Posted 14 August 2009 - 02:29 AM

Hi all, long time no see! :) Hope you're all good!

I'm writing out a calendar for a booking system which shows when a date is booked.

So in the database I have a $StartDate and an $EndDate.

I'm writing out my table with this code:
<?PHP
for($i=0;$i<$days_in_month;$i++) {
$week_number = date("Week W",mktime(0, 0, 0, $value, ($i+1), $year)); // Finds out the week of the year
$weekday = date("l",mktime(0, 0, 0, $value, ($i+1), $year)); // What weekday it is today
echo "<td title=\"$week_number: $weekday\"><a href=\"\">";
if($weekday==date("l") & $i == (date("j")-1)) {
echo "<!-- This is today -->";
}
if($weekday=="Saturday"||$weekday=="Sunday") { // Is it a weekend?
echo "<b>".($i+1)."</b> ";
}
else {
echo ($i+1)."</a></td>";
}
}
}
?>


Now I'm not sure what to do next.

I need some sort of if statement, that starts a loop based on the $StartDate from the database then changes the background colour of all the dates after $StartDate till $EndDate is reached.

The idea is that the calendar would have different background colours over the dates that are booked.

Any ideas how I go about that? :)

Is This A Good Question/Topic? 0
  • +

Replies To: Start and End dates? Fill in the dates in between?

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,898
  • Joined: 08-August 08

Re: Start and End dates? Fill in the dates in between?

Posted 14 August 2009 - 05:22 AM

Your links need fixing, but this does what you're asking:
<?php
$days_in_month =31;
$value=8;
$year=2009;
$busy = array(6=>array("Morning Meeting"), 10=>array("Morning Meeting"), 12=>array("Morning Meeting"), 20=>array("Morning Meeting"));
$color = array(' bgcolor="#FF7777" ', ' bgcolor ="#FFFFFF" ');
echo "<table width=600px><tr><th>Moday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th></tr><tr>";
$i=0;
$weekday = date("l",mktime(0, 0, 0, $value, ($i-1), $year));
while($weekday != "Sunday")
{
	echo '<td></td>';
	$i--;
	$weekday = date("l",mktime(0, 0, 0, $value, $i, $year));
}
for($i=0;$i<$days_in_month;$i++) {
	if(isset($busy[$i+1]))
		$n=0;
	else
		$n=1;
	$week_number = date("W",mktime(0, 0, 0, $value, ($i+1), $year)); // Finds out the week of the year
	$weekday = date("l",mktime(0, 0, 0, $value, ($i+1), $year)); // What weekday it is today
	echo "<td ".$color[$n]." align=\"center\" title=\"$week_number: $weekday\"><a href=\"\">";
	if($weekday==date("l") & $i == (date("j")-1)) {
		echo "<!-- This is today -->";
	}
	if($weekday=="Saturday"||$weekday=="Sunday") { // Is it a weekend?
		echo "<b>".($i+1)."</b>
";
	}
	else {
		echo ($i+1)."</a></td>
";
	}
	if($weekday=="Sunday")	
		echo "</tr><tr>
";
}
?>

Was This Post Helpful? 0
  • +
  • -

#3 DCMark  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 17-July 09

Re: Start and End dates? Fill in the dates in between?

Posted 14 August 2009 - 05:54 AM

My links need fixing? Not sure what you mean!

Thanks for the code, I'll look at it now and see if I can make sense of it :D

Thanks :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1