Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

combine get_where and limit in active record codeigniter

I am little confused here.

I have a modal like this :

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

So, I use this modal to create a pagination in CI like this :

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

in view, just :

<?php echo pagination ?>

It just give me a blank page. I think in my modal get_where is the problem. Anybody can help ?

like image 990
Fadly Dzil Avatar asked Oct 31 '22 03:10

Fadly Dzil


1 Answers

The syntax of get_where() is

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

You need to change this line in your model (alter $start_row and $limit) to make it work,

$query = $this->db->get_where('tbl_requestfix', array('nama_user' => $nama_user), $limit, $start_row);
like image 70
viral Avatar answered Nov 13 '22 05:11

viral