I have a database with following entry:
Id | UserID | Date | Time
1 | 1 | 06/29/15 | d
2 | 1 | 06/30/15 | n
And i have the following php code which generates a calendar then based on the database entry, it marks the specified days with specific color:
<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$toddate = date("j");
$todmon = date("n");
for ($i=0; $i<($maxday+$startday); $i++)
{
if (($i % 7) == 0)
echo "<tr>";
$getr = mysql_query("SELECT * FROM `reservations` WHERE `UserID` = 1");
$datee = $i - $startday + 1;
$nums = mysql_num_rows($getr);
while ($row = mysql_fetch_assoc($getr))
{
$timestamp = strtotime($row['Date']);
$bookeddate = date("d", $timestamp);
$dates[$nums] = $bookeddate;
$bookedmon = date("n", $timestamp);
if ($cMonth == $bookedmon && $row['Time'] == 'd' && $bookeddate == $datee)
echo "<td title='day booked' align='center' bgcolor='orange' valign='middle' height='20px'>". ($datee) . "</td>";
else if ($cMonth == $bookedmon && $row['Time'] == 'n' && $bookeddate == $datee)
echo "<td title='Night booked' align='center' bgcolor='black' color='white' valign='middle' height='20px'>". ($datee) . "</td>";
else if ($cMonth == $bookedmon && $row['Time'] == 'c' && $bookeddate == $datee)
echo "<td title='Completely booked' align='center' bgcolor='red' valign='middle' height='20px'>". ($datee) . "</td>";
}
if($i < $startday)
echo "<td></td>";
else if ($datee == $toddate && $cMonth == $todmon)
echo "<td title='today' align='center' bgcolor='lime' valign='middle' height='20px'>". ($datee) . "</td>";
else if ($datee != $bookeddate)
echo "<td align='center' valign='middle' height='20px'>". ($datee) . "</td>";
if(($i % 7) == 6)
echo "</tr>";
}
The problem is, it shows the first date in database two times and the other date is displayed only 1 time. How do I manage to display both dates only one time.
You may need to run the php code on your end.