Jump to content

Calendar Not Working!!!


oilyray

Recommended Posts

Hi everyone

This is my first post so i'm hoping someone out there can solve this problem for me

 

I would like to create a calendar (in month view) that shows when a booking has been made by changing the background colour of the cell.

 

I've tried for hours and hours but can't seem to get it. the code i am using is:

---------------------------------------------------------------------------------------------------

//Gets blank days

for ($i = 0; $i < $theday; $i++)

{

?>

<td> </td>

<?

}

for ($list_day = 1; $list_day <= $daysinmonth; $list_day++)

{

//checks to see if there are any records from the database. If there are we need to plot the bookings on the calendar.

if ($num >= 1)

{

  $b=0;

  while ($b < $num)

  {

    $temp=mysql_result($data,$b,"lastdate");

    $status=mysql_result($data,$b,"BookingStatus");

    $StatusID=mysql_result($data,$b,"StatusID");

 

    if($list_day==$temp)

    {

 

if ($StatusID==0)

{

echo "<td bgcolor='#333333'>$list_day</td>";

}

if ($StatusID==1)

{

echo "<td bgcolor='#0066FF'>$list_day</td>";

}

if ($StatusID==2)

{

echo "<td bgcolor='#666666'>$list_day</td>";

}

if ($StatusID==3)

{

echo "<td bgcolor='#66CC00'>$list_day</td>";

}

if ($theday == 6)

{

echo '</tr>';

echo '<tr>';

$theday = -1;

}

$theday++;

}

else

{

echo "<td>";

echo $list_day;

echo '</td>';

if ($theday == 6)

{

echo '</tr>';

echo '<tr>';

$theday = -1;

}

$theday++;

}

//$b++;

} //end while loop

}

 

The recordset used is:

$data = mysql_query("SELECT SUBSTRING(EventDate, 9, 2) AS lastdate, EventDate, Confirmed, bs.StatusID, BookingStatus FROM events AS ev INNER JOIN bookingstatus AS bs on ev.StatusID = bs.StatusID where vehicle=1 AND SUBSTRING(EventDate, 6, 2)=$month and SUBSTRING(EventDate, 1,4)=$year and ev.StatusID <> 0 and Display=1") or die(mysql_error());

$num=mysql_numrows($data);

 

Thanks for looking

 

Chris

Link to comment
https://forums.phpfreaks.com/topic/199232-calendar-not-working/
Share on other sites

Thank you adRock

 

The query does return records.

 

I have just managed to get it working to some degree with the help from another PHPFreak - can't remember his/her name.

 

Here is the code that works for me - just need to spend some time tarting it up. Thanks again

<?php

include('functions.php');

 

$date=time();

$day=date('d',$date);

$month=date('m',$date);

$year=date('Y',$date);

$first_day=mktime(0,0,0,$month,1,$year);

$title=date('F',$first_day);

$day_of_week=date('D',$first_day);

switch($day_of_week)

{

case "Sun": $blank=0;break;

case "Mon":$blank=1;break;

case "Tue": $blank=2;break;

case "Wed":$blank=3;break;

case "Thu": $blank=4;break;

case "Fri":$blank=5;break;

case "Sat": $blank=6;break;

}

$days_in_month=cal_days_in_month(0,$month,$year);

 

$LP1 = mysql_query("SELECT SUBSTRING(EventDate, 9, 2) AS lastdate, EventDate, Confirmed, bs.StatusID, BookingStatus FROM events AS ev INNER JOIN bookingstatus AS bs on ev.StatusID = bs.StatusID where vehicle=1 AND SUBSTRING(EventDate, 6, 2)=2 and SUBSTRING(EventDate, 1,4)=2010 and ev.StatusID <> 0 and Display=1") or die(mysql_error());

$LP1num=mysql_numrows($LP1);

 

echo "<table border=1 width=294>";

echo "<tr><th colspan=7>Launch Pad 1</th></tr>";

echo "<tr><th colspan=7>$title -  $year</th></tr>";

echo "<tr>";

 

$dz=array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

 

//array 2 - days in the month

while ($array = mysql_fetch_array($LP1))

{

 

$special[] = $array[0];

}

 

foreach($dz as $value)

{

print "<td width=42> $value </td>";

}

echo "</tr>";

$day_count=1;

echo "<tr>";

while ($blank>0)

{

echo "<td></td>";

$blank--;

$day_count++;

}

$day_num=1;

while ($day_num<=$days_in_month)

{

$day_num_t = $day_num;

foreach ($special as $value)

{

if($value == $day_num)

{

$day_num_t = '<a href="/book.php?day='.$day_num.'"><font color="darkgreen"> '.$day_num.' </font></a>';

}

unset($value);

 

echo "<td> $day_num_t </td>";

$day_num++;

$day_count++;

if($day_count>7)

{

echo "</tr><TR>";

$day_count=1;

}

}

while($day_count>1 && $day_count<7)

{

echo "<td> </td>";

$day_count++;

}echo "</tr></table>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.