javascript - 制作日历的问题

标签 javascript php jquery mysql

我试图制作一个带有日历的预订系统,但现在有点卡住了。这个过程或多或少是这样的

首先,我构建一个链接。

function __construct($link) {
    $this->link = $link;    
}


然后我做日历

function make_calendar($selected_date, $back, $forward, $day, $month, $year) {

    // $day, $month and $year are the $_GET variables in the URL
    $this->day = $day;    
    $this->month = $month;
    $this->year = $year;

    // $back and $forward are Unix Timestamps of the previous / next month, used to give the back arrow the correct month and year 
    $this->selected_date = $selected_date;       
    $this->back = $back;
    $this->back_month = date("m", $back);
    $this->back_year = date("Y", $back); // Minus one month back arrow

    $this->forward = $forward;
    $this->forward_month = date("m", $forward);
    $this->forward_year = date("Y", $forward); // Add one month forward arrow    

    // Make the booking array
    $this->make_booking_array($year, $month);

}


最后,我进行预订

function make_booking_array($year, $month, $j = 0) { 

    $stmt = $this->link->prepare("SELECT name, date, start FROM bookings WHERE date LIKE  CONCAT(?, '-', ?, '%')"); 

    $this->is_slot_booked_today = 0; // Defaults to 0

    $stmt->bind_param('ss', $year, $month); 
    $stmt->bind_result($name, $date, $start);   
    $stmt->execute();
    $stmt->store_result();

    while($stmt->fetch()) {    

        $this->bookings_per_day[$date][] = $start;

        $this->bookings[] = array(
            "name" => $name, 
            "date" => $date, 
            "start" => $start        
        ); 

        // Used by the 'booking_form' function later to check whether there are any booked slots on the selected day        
        if($date == $this->year . '-' . $this->month . '-' . $this->day) {
            $this->is_slot_booked_today = 1;
        } 

    }

    // Calculate how many slots there are per day
    $this->slots_per_day = 0;   
    for($i = strtotime($this->booking_start_time); $i<= strtotime($this->booking_end_time); $i = $i + $this->booking_frequency * 60) {
        $this->slots_per_day ++;
    }   

    $stmt->close();     
    $this->make_days_array($year, $month);    

} // Close function


错误出现在此最后一个函数上:

Fatal error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\dashboard\aa\calendar_new\classes\class_calendar.php on line 73


在准备$ stm之后。我的想法是construction of the link不正确,或者我在prepare()函数上犯了一个错误

谢谢你的帮助。

最佳答案

一件事是您需要在bind_result之前执行

   $stmt->bind_param('ss', $year, $month); 
    $stmt->execute();
    $stmt->bind_result($name, $date, $start);  

关于javascript - 制作日历的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44140190/

相关文章:

javascript - jQuery 将字符串转换为跨多个实例

php - 选择重构而不是完全重写的标准

php - 如何将表单输入设置为 Json 打印 php 文件中的变量?

jquery - 用HTML5和Canvas画出网站效果

javascript - 按下回车键不会在 Mozilla 中打开下拉菜单

php - MySQL 从一列中选择所有数据

javascript - Node.JS - 通过 Alexa 说出查询结果

javascript - JS加法游戏: how do I display 4 possible answers, 其中3个是随机的,1个是正确答案? (包括代码笔)

javascript - 即使 EventQueue 中有 "non-essential"个东西,如何让 NodeJS 终止?

c# - ASP.Net:使用 Javascript 和 AJAX 构建多语言网站的方法