0

I am implementing a soldout feature for a tour website. This feature will allow the admin to remove some dates from booking calendar if all seats are soldout on that particular date.

I am storing these soldout dates in mysql database in one single row and fetching them as follow:

    <?php
$conn = mysqli_connect("localhost", "root", "");
mysqli_select_db($conn, "vendors");



$result = mysqli_query($conn , "SELECT * FROM editor_data where tour_id = 1") or die (mysqli_error ($conn));
$row = mysqli_fetch_array($result);

$checked = explode(',' , $row['soldout']);
$arrlength = count($checked);


$from = $row['fromdate'];
$to = $row['Todate'];

?>

Now to disable dates this is what I am doing. But it is not working. Please help me!

$(function() {
        $('#iDate').datepicker({
            showButtonPanel: true,
            dateFormat: 'yy-mm-dd',
            beforeShowDay: checkAvailability

        });
    });

var $myBadDates = new Array('<?php 
            for($x = 0; $x <  $arrlength; $x++) {
            echo '"'; echo $checked[$x]; echo '"';
            echo " , ";
            }
            ?>');

function checkAvailability(mydate){
var $return=true;
var $returnclass ="available";
$checkdate = $.datepicker.formatDate('yy-mm-dd', mydate);
for(var i = 0; i < $myBadDates.length; i++)
    {    
       if($myBadDates[i] == $checkdate)
          {
        $return = false;
        $returnclass= "unavailable";
        }
    }
return [$return,$returnclass];
}
  • Possible duplicate of http://stackoverflow.com/questions/15400775/jquery-ui-datepicker-disable-array-of-dates – Charlotte Dunois Aug 22 '15 at 20:38
  • Use json_encode() to output php arrays. Your approach is really ugly. Show the actual source version of what `$myBadDates` looks like – charlietfl Aug 22 '15 at 20:39

0 Answers0