第一页显示没有错误但是当我点击分页中的'2'页面按钮它给出了这个错误: 如果有人可以请查看此代码,并告诉我为什么它不起作用。提前谢谢。
发生数据库错误
错误号码:1064
Erreur desyntaxeprèsde''20',20'àlaligne 1
SELECT * FROM avto WHERE category = 'yengil' ORDER BY id DESC LIMIT '20', 20
文件名:D:/wamp/www/avtosavdo.uz/application/models/News_model.php
行号:30
这是我的控制器代码:
public function prisepNews()
{
$this->pagination('prisepnews', 'prisep');
$title['title'] = 'Прицеп';
$this->load->view('templates/navbar', $title);
$this->load->view('news/allNews', $data);
}
public function pagination($url, $value)
{
$config['base_url'] = base_url() . 'index.php/news/'.$url.'/';
$config['total_rows'] = $this->news_model->record_count($value);
$config['per_page'] = 20;
$config['uri_segment'] = 3;
$config['num_links'] = 3;
$config['first_link'] = 'Биринчи';
$config['last_link'] = 'Охирги';
$config['next_link'] = 'Кейинги';
$config['prev_link'] = 'Олдинги';
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['news'] = $this->news_model->get_news($config['per_page'], $page, $value);
$data['pagination'] = $this->pagination->create_links();
return $data;
}
这是我的模型代码:
$sql = "SELECT * FROM avto WHERE category = ? ORDER BY id DESC LIMIT ?, ?";
$query = $this->db->query($sql, array($category, $start, $limit));
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row) {
$data[] = $row;
}
return $data;
}
return false;
答案 0 :(得分:0)
LIMIT '20'
中的引号会产生问题。
您需要将查询更改为
$this->db->select('*');
$this->db->where("category",$category);
$this->db->order_by("id","DESC");
$query = $this->db->get('avto', $limit, $start);
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row) {
$data[] = $row;
}
return $data;
}
return false;