Welcome Guest, Not a member yet? Register   Sign In
Problem with WHERE and pagination
#7

[eluser]Otemu[/eluser]
Hi I give you example code of pagination so you may use it or redefine for your purpose

Controller
Code:
//retrieve total rows
$numrows = $this->M_MyTable->getAllRecords();
$config['base_url'] = base_url().'mySite/';
$config['total_rows'] = $numrows;
$config['per_page'] = '2';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';

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

//url segment is the actual pagination number which will be used in the model for the offset  
$data['myRecords'] = $this->M_MyTable->getTheRecords($config['per_page'],$this->uri->segment(2));
$this->load->vars($data);
$this->load->view('myViewPage');
Model
Code:
//total number of recordss
function getAllRecords() {
$data = array();
$this->db->select('field1, field2, field3');
$this->db->from('myTable');
$this->db->limit(200);
$Q = $this->db->get();
$total = $Q->num_rows();
$data = $total;
$Q->free_result();
return $data;
}

//retrieve records
function getTheRecords($lmt, $off) {
$data = array();
$this->db->select('field1, field2, field3');
$this->db->from('myTable');
$this->db->limit($lmt);
$this->db->offset($off);
$Q = $this->db->get();
if ($Q-> num_rows() > 0){
foreach ($Q-> result_array() as $row){
  $data[] = $row;
  }
}  
$Q->free_result();
return $data;
}
Views
Code:
foreach($myRecords as $row){
echo $row['field1'].'<br />'.$row['field1'].'<br />'.$row['field1'].'<br />';
}
echo $this->pagination->create_links();

Hope this all makes sense and helps


Messages In This Thread
Problem with WHERE and pagination - by El Forum - 11-21-2012, 08:32 AM
Problem with WHERE and pagination - by El Forum - 11-21-2012, 08:53 AM
Problem with WHERE and pagination - by El Forum - 11-21-2012, 10:38 AM
Problem with WHERE and pagination - by El Forum - 11-21-2012, 11:15 AM
Problem with WHERE and pagination - by El Forum - 11-21-2012, 12:01 PM
Problem with WHERE and pagination - by El Forum - 11-22-2012, 04:42 AM
Problem with WHERE and pagination - by El Forum - 11-22-2012, 04:47 AM
Problem with WHERE and pagination - by El Forum - 11-22-2012, 08:30 AM
Problem with WHERE and pagination - by El Forum - 11-23-2012, 07:27 AM
Problem with WHERE and pagination - by El Forum - 11-23-2012, 07:44 AM
Problem with WHERE and pagination - by El Forum - 11-23-2012, 08:13 AM
Problem with WHERE and pagination - by El Forum - 11-23-2012, 08:32 AM
Problem with WHERE and pagination - by El Forum - 11-23-2012, 08:51 AM
Problem with WHERE and pagination - by El Forum - 11-23-2012, 09:46 AM
Problem with WHERE and pagination - by El Forum - 11-23-2012, 10:37 AM
Problem with WHERE and pagination - by El Forum - 11-23-2012, 10:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB