我想使用CodeIgniter创建分页但我收到以下错误
Fatal error: Call to a member function query() on a non-object in /home/eheuristic10/php/courtgenie/application/models/kicker_model.php on line 338
我的模特是
function ticketCount() {
$query = $this->db->query("SELECT count(*) as c FROM ci_ticket_details where userid='" . 2 . "' and activity_status = '0' LIMIT 1");
$rows = $query->row_array();
return $rows['c'];
}
我的分页类是
function attorney_request(){
$this->load->library('pagination');
$data['ticketCount'] = $this->kicker_model->ticketCount();
$config = array();
$config["base_url"] = 'http://localhost/courtgenie/index.php/kicker/attorney_request';
$config["total_rows"] = $this->kicker_model->ticketCount();
$config["per_page"] = 2;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$data["activeClient"] = $this->kicker_model->activeTicketsView($config["per_page"], $page);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('attorney_request',$data);
}
else{
redirect('home', 'refresh');
}
}
如果我不使用分页类,那么我的分页将正常工作
由于
答案 0 :(得分:0)
您的SQL无效:
$this->db->query("SELECT count(*) as c FROM ci_ticket_details where userid='" . 2 . "' and activity_status = '0' LIMIT 1");
您的用户ID不能是' . 2 . '
。
您还在使用 CI ,但为什么不使用 ACTIVE RECORD 来调用这样一个简单的SQL调用?节省时间使用AR ...
http://ellislab.com/codeigniter/user-guide/database/active_record.html
同时... 强>
您的if
语句的缩进格式很差,而且它已被破坏,有一个孤独的else
而您的attorney_request()
过早终止。
答案 1 :(得分:0)
在模型中尝试这个
function ticketCount() {
$this->db->select('count(*) as c');
$this->db->from('ci_ticket_details');
$this->db->where('userid', 2);
$this->db->where('activity_status', 0);
$this->db->limit(1,0);
$query = $this->db->get()->row();
return $query->c;
}