制作日历的问题

时间:2017-05-23 16:20:27

标签: 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()函数上犯了错误

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

有一件事是你需要在bind_result

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