Availability Calendar not showing selected dates
Moderator: General Moderators
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Availability Calendar not showing selected dates
I am using an availability scrip from http://www.phpjabbers.com/free-availabi ... ar-script/ . what seems to be happening if on the actual month (that it is when i add a new date it highlights all that dates added ok but addng earlier or later dates is intermittent on what it is displaying for example i could add 23,24,25 september and they are displayed ok but then go to add the 3rd september and it wont show. (even though all the dates are stored in the DB they are not showing in the calender. it very intermittent on dates so hard to pin down the issue or what to show here at the moment.
dates are stored in 2014-07-27 format (this is 27th Aug 2014)
thanks in advance
dates are stored in 2014-07-27 format (this is 27th Aug 2014)
thanks in advance
Re: Availability Calendar not showing selected dates
Please post the code in question and maybe some of the rows from the DB; a few that work and at least one that doesn't. Telling us that some black box code gives inconsistent results gives us nothing to work with.
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: Availability Calendar not showing selected dates
here is the calender.phpCelauran wrote:Please post the code in question and maybe some of the rows from the DB; a few that work and at least one that doesn't. Telling us that some black box code gives inconsistent results gives us nothing to work with.
Code: Select all
<?php
error_reporting(0);
include("config.php");
/// get current month and year and store them in $cMonth and $cYear variables
(intval($_REQUEST["month"])>0) ? $cMonth = $_REQUEST["month"] : $cMonth = date("n");
(intval($_REQUEST["year"])>0) ? $cYear = $_REQUEST["year"] : $cYear = date("Y");
if ($cMonth<10) $cMonth = '0'.$cMonth;
// generate an array with all unavailable dates
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE `date` LIKE '".$cYear."-".$cMonth."-%'";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysql_fetch_assoc($sql_result)) {
$unavailable[] = $row["date"];
}
// calculate next and prev month and year used for next / prev month navigation links and store them in respective variables
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = intval($cMonth)-1;
$next_month = intval($cMonth)+1;
// if current month is Decembe or January month navigation links have to be updated to point to next / prev years
if ($cMonth == 12 ) {
$next_month = 1;
$next_year = $cYear + 1;
} elseif ($cMonth == 1 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
?>Code: Select all
<table width="800">
<tr>
<td class="mNav"><a href="javascript:LoadMonth('<?php echo $prev_month; ?>', '<?php echo $prev_year; ?>')"><<</a></td>
<td colspan="5" class="cMonth"><?php echo date("F, Y",strtotime($cYear."-".$cMonth."-01")); ?></td>
<td class="mNav"><a href="javascript:LoadMonth('<?php echo $next_month; ?>', '<?php echo $next_year; ?>')">>></a></td>
</tr>
<tr>
<td class="wDays">M</td>
<td class="wDays">T</td>
<td class="wDays">W</td>
<td class="wDays">T</td>
<td class="wDays">F</td>
<td class="wDays">S</td>
<td class="wDays">S</td>
</tr>
<?php
$first_day_timestamp = mktime(0,0,0,$cMonth,1,$cYear); // time stamp for first day of the month used to calculate
$maxday = date("t",$first_day_timestamp); // number of days in current month
$thismonth = getdate($first_day_timestamp); // find out which day of the week the first date of the month is
$startday = $thismonth['wday'] ; // 0 is for Sunday and as we want week to start on Mon we subtract 1
if (!$thismonth['wday']) $startday = 7;
for ($i=1; $i<($maxday+$startday); $i++) {
if (($i % 7) == 1 ) echo "<tr>";
if ($i < $startday) { echo "<td> </td>"; continue; };
$current_day = $i - $startday + 1;
(in_array($cYear."-".$cMonth."-".$current_day,$unavailable)) ? $css='booked' : $css='available'; // set css class name based on date availability
echo "<td class='".$css."'>". $current_day . "</td>";
if (($i % 7) == 0 ) echo "</tr>";
}
?>
</table>
showing on the calender
date
2014-09-26
2014-09-25
2014-09-24
displayed in the db but not showing
2014-09-03
Re: Availability Calendar not showing selected dates
It's checking 2014-09-3 against 2014-09-03, which isn't a match. You need to pad the dates.
Change this:
to this:
Change this:
Code: Select all
$current_day = $i - $startday + 1;Code: Select all
$current_day = str_pad(($i - $startday + 1), 2, '0', STR_PAD_LEFT);-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: Availability Calendar not showing selected dates
yes that done it, thanks, any dates that are single numbers i.e 1,2,3,4 etc.. would cause the error?Celauran wrote:It's checking 2014-09-3 against 2014-09-03, which isn't a match. You need to pad the dates.
Change this:to this:Code: Select all
$current_day = $i - $startday + 1;Code: Select all
$current_day = str_pad(($i - $startday + 1), 2, '0', STR_PAD_LEFT);
Re: Availability Calendar not showing selected dates
That's right. Because of how it iterates over the dates, you'll need to pad 1-9 in order to get a match.
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: Availability Calendar not showing selected dates
oh ok, thanks for thatCelauran wrote:That's right. Because of how it iterates over the dates, you'll need to pad 1-9 in order to get a match.