[eluser]bhakti.thakkar[/eluser]
i have a page in which i display all the projects of a particular client. e.g. there are 24 records for a particular client. but i get all the 24 records at a stretch in my view. i have specified 5 records per page but it doesnt work. there are proper ‹ First < 1 2 3 4 5 > on my view page but all 24 records are shown on all the links. what is wrong ? please help me
Controller : projects.php:
Code:
function index()
{
$start = (int) $this->uri->segment(3);
($start) ? $lower = $start : $lower = 0;
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/projects/index/';
$config['uri_segment'] = 3;
$config['total_rows'] = $this->projects_model->ProjectCount(); // returns 24 rows
$offset = (int) $this->uri->segment(3, 0);
$config['per_page'] = '5';
// $config['num_links'] = 5;
$config['full_tag_open'] = '<p class="pagination">';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['query'] = $this->projects_model->getProjects($lower, $config['per_page']);
$data['total_rows'] = ($data['query']) ? $data['query']->num_rows() : 0;
$data['message'] = ($this->session->flashdata('message') != '') ? '<p class="error">'.$this->session->flashdata('message').'</p>' : '';
$data['page_title'] = 'Projects';
$this->load->view('projects/index', $data);
}
my view :
Code:
<?php
if (isset($pagination)) {
echo $pagination;
}
?>
<table class="stripe" id="invoiceListings">
<tbody id="invoiceRows">
<tr>
<th class="invNum" width="8%">Sr. no.</th>
<th class="invNum">Project ref.</th>
<th class="dateIssued">Name</th>
</tr>
<?php
if (isset($total_rows) && $total_rows == 0):
?>
<tr>
<td colspan="5">No records found
</td>
</tr>
<?php
else:
$i=0;
foreach($query->result() as $row):
$i++;
?>
<tr>
<td><?=$i?></td>
<td><?php echo anchor('invoices/view/'.$row->Project_ID,$row->Project_ID);?></td>
<td><?php echo anchor('invoices/view/'.$row->Project_VC, htmlentities($row->Project_VC));?></td>
</tr>
<?php
endforeach;
endif;
?>
</tbody>
</table>
Model :
[code]
function getProjects()
{
return $this->_getProjects();
}
// --------------------------------------------------------------------
function _getProjects($offset=0, $limit=100)
{
$relation_id = $this->session->userdata('srelation_id');
// check for any invoices first
if ($this->db->count_all_results('Project_T') < 1)
{
return FALSE;
}
$this->db->select(' * ');
$this->db->where(" Relation_ID = '$relation_id' and Deleted_DT is null");
$this->db->offset($offset);
$this->db->limit($limit);
return $this->db->get('Project_T');
}
Thanks in anticipation
[/code]