将get_where和limit组合在活动记录codeigniter中

时间:2015-05-30 07:12:35

标签: php codeigniter

我在这里很困惑。

我有一个这样的模态:

public function selectRequestPerUser($nama_user, $start_row, $limit) {
    $query = $this->db->get_where('tbl_requestfix', array('nama_user' => $nama_user), $start_row, $limit);
    return $query->result_array();
}

所以,我使用这个模态在CI中创建一个分页:

$nama = $this->session->userdata('nama');
$start_row = $this->uri->segment(2);
$per_page = 3;

if(trim($start_row) == ''){
  $start_row = 0;
};

$this->load->library('pagination');
$config['base_url'] = base_url().'control_closing/';
$config['total_rows'] = $total_rows;
$config['per_page'] = $per_page;

$this->pagination->initialize($config);

$data['pagination'] = $this->pagination->create_links();

$request = $this->model_request->selectRequestPerUser($nama, $start_row, $per_page);
$data['data_request'] = $request;
$this->load->view('view_closing', $data);

在视图中,只是:

<?php echo pagination ?>

它只是给我一个空白页面。我认为在我的模态get_where是问题所在。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

get_where()的语法是

$query = $this->db->get_where('mytable', array('id' => $id), $limit, $offset);

您需要在模型中更改此行(更改$start_row$limit)以使其正常工作,

$query = $this->db->get_where('tbl_requestfix', array('nama_user' => $nama_user), $limit, $start_row);