duanaiguang1960 2017-05-23 16:20
浏览 57

制作日历时出现问题

im trying to make a booking system with a calendar but im a bit stuck right now. The process more or less is like this

First I construct a link.

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

Then I make the calendar

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);

}

And finally i make the booking array

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

The error appears on this last 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

After the preparation of the $stm. My thoughts is that either the construction of the link is not correct, or I have made a mistake on the prepare()function

Thanks for your help.

  • 写回答

1条回答 默认 最新

  • dongqiao6730 2017-05-23 16:49
    关注

    One thing is that you need to execute before bind_result

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

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作