Hope, you will have the basic knowledge of php, mysql and codeigniter.
Pagination Using Codeigniter by passing parameter:-
Model Page :
class Model_page extends CI_Model
{
public function __construct()
{
parent::__construct();
// Your own constructor code
}
// Counting no of rows in your table ---
public function record_count()
{
return $this->db->count_all('table_name');
}
//Fetching the value from database --------------------------------
public function getYourMethod($limit,$start, $parameter)
{
$result= array();
//First way to write the query without any clause----
$this->db->limit($limit,$start);
$query = $this->db->get('table_name');
//With Where Clause :----------
$this->db->limit($limit,$start);
$this->db->where('table_entity',$parameter) // This parameter should be defined in controller or model itself here i am defining in controller and passing through method.
$query = $this->db->get('table_name');
//Second way--------------------------------------------
$query = $this->db->get_where('table_name', array('table_entity' => $parameter), $limit, $start);
// i am taking array for where Clause by taking array you can pass more than one where condition at once---
if ($query->num_rows() > 0)
{
while($row = $query->_fetch_assoc())
{
$result[] = $row;
}
}
return $result;
}
}
Controller Page :
class Controller_page extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('pagination');
$this->load->model("model_page");
}
public function Your_method()
{
$parameter = $_REQUEST['parameter']; //this is your passing parameter-----
$config = array();
$config["base_url"] = base_url() . "index.php/controller_page/Your_method";
$config["total_rows"] = $this->model_page->record_count();
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$config['suffix'] = '?'.http_build_query($_REQUEST, '', "&");
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["your_data"] = $this->products_model->getYourMethod($config["per_page"], $page, $parameter); //Passing the parameter to your model page method---
$data["links"] = $this->pagination->create_links();
$this->load->view("view_page", $data);
}
}
View Page :
<?php foreach($your_data as $data): ?>
<?php echo $data['table_entity'] ?>
<?php endforeach;?>
<?php echo links;?>
NOTE : To use this you should have the basic knowledge of php, mysql and obviously codeigniter also.
If any problem to get this just comment, i will give my best.
Enjoy :)
Pagination Using Codeigniter by passing parameter:-
Model Page :
class Model_page extends CI_Model
{
public function __construct()
{
parent::__construct();
// Your own constructor code
}
// Counting no of rows in your table ---
public function record_count()
{
return $this->db->count_all('table_name');
}
//Fetching the value from database --------------------------------
public function getYourMethod($limit,$start, $parameter)
{
$result= array();
//First way to write the query without any clause----
$this->db->limit($limit,$start);
$query = $this->db->get('table_name');
//With Where Clause :----------
$this->db->limit($limit,$start);
$this->db->where('table_entity',$parameter) // This parameter should be defined in controller or model itself here i am defining in controller and passing through method.
$query = $this->db->get('table_name');
//Second way--------------------------------------------
$query = $this->db->get_where('table_name', array('table_entity' => $parameter), $limit, $start);
// i am taking array for where Clause by taking array you can pass more than one where condition at once---
if ($query->num_rows() > 0)
{
while($row = $query->_fetch_assoc())
{
$result[] = $row;
}
}
return $result;
}
}
Controller Page :
class Controller_page extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('pagination');
$this->load->model("model_page");
}
public function Your_method()
{
$parameter = $_REQUEST['parameter']; //this is your passing parameter-----
$config = array();
$config["base_url"] = base_url() . "index.php/controller_page/Your_method";
$config["total_rows"] = $this->model_page->record_count();
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$config['suffix'] = '?'.http_build_query($_REQUEST, '', "&");
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["your_data"] = $this->products_model->getYourMethod($config["per_page"], $page, $parameter); //Passing the parameter to your model page method---
$data["links"] = $this->pagination->create_links();
$this->load->view("view_page", $data);
}
}
View Page :
<?php foreach($your_data as $data): ?>
<?php echo $data['table_entity'] ?>
<?php endforeach;?>
<?php echo links;?>
NOTE : To use this you should have the basic knowledge of php, mysql and obviously codeigniter also.
If any problem to get this just comment, i will give my best.
Enjoy :)
No comments:
Post a Comment