I'm using codeigniter 2.1.4 and i'm trying to display all the users files on a page with pagination of 5 records per page. The pagination links work but every link shows all the records.
My Model
public function get_user_files($user_id, $keyword = NULL) {
$select = array(
'files.name as filename',
'files.id, files.remarks',
'boxes.id as box_id',
'boxes.bin_id as bin_id',
'box_types.name as box_type',
'companies.name as companyname'
);
$from = array('files','boxes','box_types','companies');
$where = array(
'files.status' => 'Warehouse',
'files.box_id' => 'boxes.id',
'boxes.box_type_id' => 'box_types.id',
'boxes.company_id' => 'companies.id',
'boxes.user_id' => $user_id
)
$this->db
->select($select)
->from($from)
->where($where);
if ($keyword) {
$this->db->like('files.name', $keyword);
}
$query = $this->db->get()->result_array();
return $query;
}
My Controller
public function retrieve_box() {
if ($this->correct_permission('client') == false) {
redirect(base_url());
}
$this->load->helper('form');
$keyword = $this->input->post('keyword');
$data['files'] = $this->File->get_user_files($this->data['user_id'], $keyword);
$total_rows = count($data['files']);
// Pagination
$this->load->library('pagination');
$config['base_url'] = base_url() . 'client/service_request/type/retrieve-box';
$config['uri_segment'] = 5;
$config['total_rows'] = $total_rows;
$config['per_page'] = 5;
$this->pagination->initialize($config);
$data['pages'] = $this->pagination->create_links();
$this->load->view('retrieve_box', $data);
}
My URL is like so
www.website.com/client/service_request/type/retrieve-box/
My View
<?php
$attributes = array('class' => 'standardForm', 'id' => 'retrieveBoxesForm');
echo form_open('', $attributes);
?>
<fieldset>
<ul>
<li>
<?php
$data_form = array(
'name' => 'keyword',
'id' => 'boxes-field1',
'class' => 'textbox2',
);
echo form_input($data_form);
?>
<?php
$data_form = array(
'class' => 'button2',
'value' => 'Search',
);
echo form_submit($data_form);
?>
</li>
</ul>
</fieldset>
<div class="clear"></div>
<?php echo form_close(); ?>
<div class="standardTable">
<table>
<thead>
<tr>
<th><span class="checkboxReplacement"><input type="checkbox" /></span></th>
<th>Type</th>
<th>Filename</th>
<th>Box ID</th>
<th>Company</th>
<th>Location</th>
<th>Remarks</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($files as $file) { ?>
<tr>
<td><span class="checkboxReplacement"><input type="checkbox" /></span></td>
<td><?php echo $file['box_type']; ?></td>
<td><?php echo $file['filename']; ?></td>
<td><?php echo $file['box_id']; ?></td>
<td><?php echo $file['companyname']; ?></td>
<td><?php echo $file['bin_id']; ?></td>
<td><?php echo $file['remarks']; ?></td>
<td>
<a href="<?php echo base_url('client/retrievebox/' . $file['box_id']); ?>">Retrieve File</a> |
<a href="<?php echo base_url('client/retrievefile/' . $file['id']); ?>">Retrieve Box</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php echo $pages; ?>
</div>
Objective When a user goes to the above link, all of his/her files are displayed but with pagination of 5 records per page.
They can search their file names to get a more specific record.
I've managed to display the links like so:
www.website.com/client/service_request/type/retrieve-box/
www.website.com/client/service_request/type/retrieve-box/5
www.website.com/client/service_request/type/retrieve-box/10
But when i click on any of the pagination links, i'm taken to the respective url but all the records are showing.
Thank you for reading this. Really struggling to find a solution.
Regards :)