php - I want to create paging on my content managed site -
i'm trying load blog type page, load entries database controller
public function blog($page){ $this->load->model("model_get"); $this->load->view("site_header"); $this->load->view("site_nav"); $counter = $this->model_get->getblogcount(); for($counter; $counter > 0; $counter --){ $data["results"] = $this->model_get->getblog($counter); $this->load->view("content_blog", $data); } } $this->load->view("site_footer"); }
and model
function getblogcount(){ $result = $this->db->count_all("blog"); return $result; }
i count entries in database call them out id. i'm trying create multiple pages expand automatically everytime enter new entry. lets have 27 entries, , want have no more 5 entries on single page, how make creates necessary 6 pages show them without loading other 3 empty entries , stuff. i'm new codeigniter , have worked asp .net, helpfull. in advance!
p.s. english isn't first language
codeigniter have own pagination class. take here : http://ellislab.com/codeigniter/user-guide/libraries/pagination.html
you can try firstly , adapt project :
public function blog($page = 0) { $this->load->library('pagination'); $this->load->helper('url'); $config['base_url'] = base_url('blog/'. $page); $config['total_rows'] = $this->model_get->getblogcount(); $config['per_page'] = 5; $this->pagination->initialize($config); $data['results'] = $this->model_get->getblog($config['per_page'], $page); $this->load->view("content_blog", $data); }
edit "getblog" function model results limit clause, :
function getblog($limit, $start) { $results = $this->db->limit($limit, $start)->get('your_blog_table'); if ($results) { return $results->result(); } return false; }
and use in view code create pagination links :
echo $this->pagination->create_links();
Comments
Post a Comment