你好我的分页不工作。
这是我的控制器类。customer_controller.php
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->model('customer_model');
$this->load->library('pagination');
}
public function index()
{
$data['title']= 'Customer';
$data['records'] = $this->customer_model->getAll();
$data['groups'] = $this->customer_model->getAllCustomerGroups();
$data['groupcodes'] = $this->customer_model->getAllCustomerGroups();
$config['base_url'] = 'customers';
$config['total_rows'] = $this->customer_model->record_count();
$config['per_page'] = 1;
$config["uri_segment"] = 3;
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["customers"] = $this->customer_model->fetch_customers($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
//$this->pagination->initialize($config);
//echo $this->pagination->create_links();
$this->load->view('include/header',$data);
$this->load->view('include/navbar',$data);
$this->load->view('customer_view', $data);
$this->load->view('include/sidebar',$data);
$this->load->view('include/footer',$data);
}
客户模型.php
public function fetch_customers($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->query('SELECT customercode, customername, customergroup, customertype, customeraddress, website FROM customercard');
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
customer_view.php
<?php
foreach ($customers as $key => $value)
{
echo '<p>'. $value->customercode . '</p>';
echo '<p>'. $value->customername . '</p>';
}
?>
我的问题是,它只是显示所有记录,而不是一次只显示 1 条记录。而且我的分页链接也没有显示。我在这里做错了什么?非常感谢您的帮助。谢谢。