CodeIgniter Forums
problem with pagination - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: problem with pagination (/showthread.php?tid=68813)



problem with pagination - programmer - 08-29-2017

i use pagination in codeigniter . and show page number but dosn't show previous and next button


controller code

PHP Code:
$config['base_url'   base_url() . 'track/category/' $title '/page/';
                    
$config['total_rows' $this->custom_model->GetcountDataByCategory('track'$id);
                    
$config['per_page']       30;
                    
$config['uri_segment'] = $this->uri->segment(5);
                    
$page                  = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;                    
                    
$this->pagination->initialize($config);
                    
$data['pagination'   $this->pagination->create_links();                    
                    
$tracks                $this->track_model->getDataByPaging($id$config['per_page'], $page); 

model code : 
PHP Code:
public function getDataByPaging($id$limit$start){
        
$publishDate strtotime(date('d F Y h:i A'));
 
       $this->db->select('t.id  tid,t.artist_id  tartistid,t.remixer tremixer,t.genre_id  tgenrei,t.category_id tcategory,t.title  ttitle,t.cover  tcover,t.energy,t.label,t.on_sale tonsale,t.featured,t.description,t.publish_date,t.release_date,t.count_download,t.key,t.bpm,t.url,t.lik,artists.id,artists.artist_name,g.id gid,g.name,cat.id catId,cat.title catTitle,');
 
       $this->db->from('track AS t');
 
       $this->db->join('artists','artists.id = t.artist_id');
 
       $this->db->join('genres AS g','g.id = t.genre_id');
 
       $this->db->join('category AS cat',"cat.id = t.category_id");
 
       $where "t.publish_date = 'NULL' OR t.publish_date <= $publishDate AND t.category_id = $id";
 
       $this->db->where($where);
 
       $this->db->order_by('t.release_date','desc');
        
$this->db->limit($limit$start);
 
       $query $this->db->get();
 
       return $query->result();


here


RE: problem with pagination - InsiteFX - 08-30-2017

For one your creating your pagination links before you get you data from the database to display.

Your create links show be last just before your load your view.


RE: problem with pagination - programmer - 08-30-2017

(08-30-2017, 02:23 AM)InsiteFX Wrote: For one your creating your pagination links before you get you data from the database to display.

Your create links show be last just before your load your view.

I did the same, but did not change. Sad


RE: problem with pagination - sasbass - 08-31-2017

Try change $config['per_page'] = 3


RE: problem with pagination - InsiteFX - 08-31-2017

It could also be your uri_segment is wrong, use your web browsers development tools
to see what the segments are being returned or echo out your segments and $page.

Most likely you will find that your $page is always returning 0.