I am getting a fatal error. What am missing here? Thanks in advance for any help. I am learning. I am trying to test to see what dates are open between certain dates.
<?php
$query = 'SELECT venueprofile.venuename, venueprofile.capacity, venueprofile.contact, venueprofile.EmailAddress, venueprofile.tele, venueprofile.st, venueprofile.city, showdate.show_date, showdateid'
. ' FROM `venueprofile` '
. ' INNER JOIN `showdate` ON venueprofile.venueid = showdate.venueid'
. ' WHERE show_date BETWEEN \'2013-06-15\' AND \'2013-06-25\''
. ' AND capacity BETWEEN 500 AND 3000 '
. ' ';
$startDate = '$date1';
$enddate = '$date2';
$dates = array($startDate);
while ($startDate != $enddate) {
$startDate = date('Y-m-d', strtotime($startDate . ' +1 day'));
$dates[] = date;
}
;
$bookings = array("2013-06-16","2013-06-20");
foreach ($dates as $date) {
if (in_array($date, $bookings)) { echo ""; }
else { echo $date . " is Open
";}}
?>
$startDate = '$date1';
$enddate = '$date2';
This doesn't work as expected; the single quotes prevent variable interpolation. Also, you don't need the quotes.
$startDate = $date1;
$enddate = $date2;
Furthermore, I would recommend changing your loop condition.
while ($startDate < $enddate) {
Doing so could prevent issues when $startDate > $enddate
before the loop starts.
Lastly, the following statement doesn't work:
$dates[] = date;
date
is a constant which you most likely have not defined. You probably meant this:
$dates[] = $startDate;
In addition to the problems that Jack has already pointed out, it seems to me it would have been a lot more efficient to use just a single loop and avoid having to build up that array of dates.
So something like this:
$bookings = array("2013-06-16","2013-06-20");
$startDate = $date1;
$enddate = $date2;
while ($startDate <= $enddate) {
if (!in_array($startDate, $bookings)) {
echo $startDate . " is Open
";
}
$startDate = date('Y-m-d', strtotime($startDate . ' +1 day'));
}
Or did you need the $dates
array for some other purpose?