如何将php变量放入datepicker

时间:2014-10-09 19:07:17

标签: php jquery datepicker

请帮助我新编程

我正在尝试使用while($ row = mysql_fetch_array($ query))基于我的数据库中的日期禁用datepicker中的特定日期

这是代码:

    <?php include"pages/config.php";
    $query=mysql_query("SELECT * FROM request");   
 while ($row = mysql_fetch_array($query)) {
 $dbDate = $row['event_date'];
}
?>
var disabledDays = ["10-21-2014", "11-15-2014", "11-17-2014"];
function disableAllTheseDays(date) {
    var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
    for (i = 0; i < disabledDays.length; i++) {
        if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
            return [false];
        }
    }
    return [true];
}

 $(function () {
$("#dp").datepicker({
    minDate: 0,
    dateFormat: 'mm/dd/yy',
    inline: true,

    dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
    beforeShowDay: disableAllTheseDays,
});
 });




   </script>

我想将日期“10-21-2014”,“11-15-2014”,“11-17-2014”更改为$ dbDate在循环中获得的所有日期。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

我不在乎:

    <?php include"pages/config.php";
        $query=mysql_query("SELECT * FROM request");   
$dbDate="";
     while ($row = mysql_fetch_array($query)) {
     $dbDate.= '"'.$row['event_date'].'",';
    }
    ?>
    var disabledDays = [<?php echo $dbDate ?>];
    function disableAllTheseDays(date) {
        var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
        for (i = 0; i < disabledDays.length; i++) {
            if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
                return [false];
            }
        }
        return [true];
    }

     $(function () {
    $("#dp").datepicker({
        minDate: 0,
        dateFormat: 'mm/dd/yy',
        inline: true,

        dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        beforeShowDay: disableAllTheseDays,
    });
     });




       </script>