Codeigniter Pagination Links Error After ID -
sorry if question duplicate, have problem codeigniter pagination. url is: http://mysite/news/category/26/(page number), have 5 data , page limit 10, generated links active on page 3, believe because of id/26/
this model :
function categpry($id){ $string_query = "select * news n join category c on n.category_id = c.id_category , n.category_id = $id order n.category_id desc"; $query = $this->db->query($string_query); $config['base_url'] = site_url('news/category/' . $id); $config['total_rows'] = $query->num_rows(); $config['per_page'] = '10'; $num = $config['per_page']; $offset = $this->uri->segment(4); $offset = ( ! is_numeric($offset) || $offset < 1) ? 0 : $offset; if(empty($offset)){ $offset = 0; } $this->pagination->initialize($config); $news = $this->db->query($string_query." limit $offset,$num"); return $nes; }
the generated links 1 - 2 - 3, should no link because have 5 data
please me on this, thank you
finally fixed change script :
function category($id){ $string_query = "select * news n join category c on n.category_id = c.id_category , n.category_id = $id order n.category_id desc"; $query = $this->db->query($string_query); $config['base_url'] = site_url('news/category/' . $id); $config['total_rows'] = $query->num_rows(); $limit = $config["per_page"] = 10; $config["uri_segment"] = 4; $config["use_page_numbers"] = true; $this->pagination->initialize($config); if($this->uri->segment(4)) $page = ($this->uri->segment(4)-1)*$limit; else $page = 1; $news= $this->db->query($string_query." limit $page,$limit"); return $news; }
thank you
Comments
Post a Comment