Welcome Guest, Not a member yet? Register   Sign In
Problem: Filter with pagination - second link doesn't save the query
#1

[eluser]Marcello Benigno[/eluser]
Hi All,

I'm newbie in CI and have a question about pagination, here is my code:

<?php
class Person extends Controller {

// num of records per page
private $limit = 4;

function Person(){
parent::Controller();

// load library
$this->load->library(array('table','validation'));

// load helper
$this->load->helper('url');

// load model
$this->load->model('personModel','',TRUE);
}

function index($offset = 0){
// offset
$uri_segment = 3;
$offset = $this->uri->segment($uri_segment);

// load data
if(isset($_POST['value']))
{
$column = $_POST['column'];
$value = $_POST['value'];
$total = $this->personModel->count_search_paged_list($column, $value, $this->limit, $offset);
var_dump($total);
$persons = $this->personModel->get_search_paged_list($column, $value, $this->limit, $offset)->result();
}
else
{
$persons = $this->personModel->get_paged_list($this->limit, $offset)->result();
$total = $this->personModel->count_all();
}

// generate pagination
$this->load->library('pagination');
$config['base_url'] = site_url('person/index/');
$config['total_rows'] = $total;
$config['per_page'] = $this->limit;
$config['enable_query_strings'] = TRUE;

//$config['query_string_segment'] = 'column='.$column.'value='.$value.'&per_page=4';

$config['uri_segment'] = $uri_segment;

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

// generate table data
$this->load->library('table');
$this->table->set_empty(" ");
$this->table->set_heading('No', 'Name', 'Gender', 'Date of Birth (dd-mm-yyyy)', 'Actions');
$i = 0 + $offset;
foreach ($persons as $person){
$this->table->add_row(++$i, $person->name, strtoupper($person->gender)=='M'? 'Male':'Female', date('d-m-Y',strtotime($person->dob)),
anchor('person/view/'.$person->id,'view',array('class'=>'view')).' '.
anchor('person/update/'.$person->id,'update',array('class'=>'update')).' '.
anchor('person/delete/'.$person->id,'delete',array('class'=>'delete','onclick'=>"return confirm('Are you sure want to delete this person?')"))
);
}
$data['table'] = $this->table->generate();

// load view
$this->load->view('personList', $data);
}

function add(){
// set validation properties
$this->_set_fields();

// set common properties
$data['title'] = 'Add new person';
$data['message'] = '';
$data['action'] = site_url('person/addPerson');
$data['link_back'] = anchor('person/index/','Back to list of persons',array('class'=>'back'));

// load view
$this->load->view('personEdit', $data);
}


}
?>

//--------------------------- model ----------------------------------------
<?php
class PersonModel extends Model {

private $tbl_person= 'tbl_person';

function Person(){
parent::Model();
}

function count_search_paged_list($column, $value, $limit, $offset)
{
$this->db->where($column, $value);
$query = $this->db->get($this->tbl_person);
if($query)
{
return $query->num_rows();
}
else
{
return $this->db->count_all($this->tbl_person);
}
}

function list_all(){
$this->db->order_by('id','asc');
return $this->db->get($tbl_person);
}

function count_all(){
return $this->db->count_all($this->tbl_person);
}

function get_paged_list($limit = 10, $offset = 0){
$this->db->order_by('id','asc');
return $this->db->get($this->tbl_person, $limit, $offset);
}

function get_search_paged_list($column, $value, $limit = 10, $offset = 0){
$this->db->order_by('id','asc');
$this->db->where($column, $value);
return $this->db->get($this->tbl_person, $limit, $offset);
}


}
?>

When I clicked my Query Work's fine, but the second link of pagination show the query "select * from tbl_person".

How i can save the query result's?

Thanks in advance




Theme © iAndrew 2016 - Forum software by © MyBB