Thursday, 15 January 2015

php - How to configure CodeIgniter pagination? -



php - How to configure CodeIgniter pagination? -

here's code:

$config['base_url'] = base_url() . 'settings/profile/'; $config['total_rows'] = $data['count_user_posts']; $config['per_page'] = 3; $offset = ($this->uri->segment('3') * $config['per_page']) / 2; $this->pagination->initialize($config); $config['use_page_numbers'] = true; $data['user_posts'] = $this->post_model->get_user_posts($_session['user_id'], $config['per_page'], $config['offset']);

problem when click on 2 or other link, shows info previous page also. solution - doing wrong?

here example, how had implemented

in controller

function index() { $this->load->library('pagination'); $config = array(); $config["base_url"] = base_url() . "city/index"; $config["total_rows"] = $this->city_model->record_count(); $config["per_page"] = 20; $config["uri_segment"] = 4; $this->pagination->initialize($config); $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0; $data["city"] = $this->city_model->get_cities($config["per_page"], $page); $data["links"] = $this->pagination->create_links(); }

in model

function record_count() { homecoming $this->db->count_all("city"); } function get_cities($limit,$start) { $this->db->limit($limit,$start); $this->db->select('*'); $this->db->from('city'); $this->db->order_by('city_name'); $query = $this->db->get(); if ($query->num_rows() > 0) { foreach ($query->result() $row) { $data[] = $row; } homecoming $data; } homecoming false; }

php codeigniter

No comments:

Post a Comment