hi,
I want to high light booking dates in a calendar. start_date and date.. both has to be high light.
You booking start date is 1/1/2003 and end is 2/2/2003.
All the days between start_date and end_date has to be high light.
I know how to how light start_date using array and check with day of calender in a month. but How do i high light all days between start and end date ??
here is my code
<?
// list of names for days and months
$days = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
// number of days in each month
$totalDays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
// set up some variables to identify the month, date and year to display
if(!$currYear) { $currYear = date("Y"); }
if(!$currMonth) { $currMonth = date("n"); }
if(!$currDay) { $currDay = date("j"); }
// if leap year, modify $totaldays array appropriately
if (date("L", mktime(0,0,0,$currMonth,1,$currYear)))
{
$totalDays[2] = 29;
}
// set up variables to display previous and next months correctly
// defaults for previous month
$prevMonth = $currMonth-1;
$prevYear = $currYear;
// if January, decrement year and set month to December
if ($prevMonth < 1)
{
$prevMonth=12;
$prevYear--;
}
// defaults for next month
$nextMonth = $currMonth+1;
$nextYear = $currYear;
// if December, increment year and set month to January
if ($nextMonth > 12)
{
$nextMonth=1;
$nextYear++;
}
// get down to displaying the calendar
// find out which day the first of the month falls on
$firstDayOfMonth = date("w", mktime(0,0,0,$currMonth,1,$currYear));
include("config.php");
// open a connection to the database
$connection = mysql_connect($server, $user, $pass);
// formulate the SQL query - same as above
$query = "SELECT DISTINCT start_date from calendar where start_date >= '" . $currYear . "-" . sprintf("%02d", $currMonth) . "-01' and start_date <= '" . $currYear . "-" . sprintf("%02d", $currMonth) . "-" . $totalDays[$currMonth] . "'";
// run the query on the database
$result = mysql_db_query($db,$query ,$connection);
$x=0;
$dateList=array();
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
$dates = explode("-", $row["start_date"]);
$dateList[$x] = $dates[2];
$x++;
}
}
// close connection
mysql_close($connection);
?>
<table border="0" cellpadding="2" cellspacing="5">
<!-- month display -->
<tr>
<td><a href="<? echo $PHP_SELF; ?>?currMonth=<? echo $prevMonth; ?>&currYear=<? echo $prevYear; ?>"><font face="Arial" size="-2"><<</font></a></td>
<td colspan="5" align="CENTER"><font face="Arial" size="-1"><b><? echo $months[$currMonth] . " " . $currYear; ?></b></font></td>
<td><a href="<? echo $PHP_SELF; ?>?currMonth=<? echo $nextMonth; ?>&currYear=<? echo $nextYear; ?>"><font face="Arial" size="-2">>></font></font></a></td>
</tr>
<!-- day names -->
<tr>
<?
for ($x=0; $x<7; $x++)
{
echo "<td><font face=Arial size=-2>" . substr($days[$x],0,3) . "</font></td>";
}
?>
</tr>
<!-- start displaying dates -->
<tr>
<?
// display blank spaces until the first day of the month
for ($x=1; $x<=$firstDayOfMonth; $x++)
{
// this comes in handy to find the end of each 7-day block
$rowCount++;
echo "<td><font face=Arial size=-2> </font></td>\n";
}
// counter to track the current date
$dayCount=1;
while ($dayCount <= $totalDays[$currMonth])
{
// use this to find out when the 7-day block is complete and display a new row
if ($rowCount % 7 == 0)
{
echo "</tr>\n<tr>\n";
}
// if today, display in different colour
// print date
if ($dayCount == date("j") && $currYear == date("Y") && $currMonth == date("n"))
{
#echo "<td align=center bgcolor=Silver><font face=Arial size=-1><a href=day.view.php?currYear=" . $currYear . "&currMonth=" . $currMonth . "&currDay=" . $dayCount . ">" . $dayCount. "</a></font>";
echo "<td align=center bgcolor=Silver><font face=Arial size=-1><a href=\"javascript:cal_action($dayCount, $currMonth, $currYear)\";>$dayCount</a></font>";
}
else
{
echo "<td align=center><font face=Arial size=-1><a href=\"javascript:cal_action($dayCount, $currMonth, $currYear)\";>" . $dayCount . "</a></font>";
#echo "<td align=center><font face=Arial size=-1><a href=day.view.php?currYear=" . $currYear . "&currMonth=" . $currMonth . "&currDay=" . $dayCount . ">" . $dayCount . "</a></font>";
}
for ($y=0; $y<sizeof($dateList); $y++)
{
//echo $dateList[$y];
if ($dateList[$y] == $dayCount)
{
echo "<font face=Arial color=red size=-4>+</font>";
}
}
echo "</td>\n";
// increment counters
$dayCount++;
$rowCount++;
}
?>
cheers..