CodeIgniter Forums
Pagination not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Pagination not working (/showthread.php?tid=72711)



Pagination not working - firas - 01-30-2019

I am making pagination for my page because of too many data from the database, I try an online tutorial, I can show the data from the database, but when I click next or second page on the pagination, it didn't work. 

this is my controller : 

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Exhibitions extends CI_Controller {
 
   
    function __construct
() {
 
       parent::__construct();
 
       //load pagination library
 
       $this->load->library('pagination');
 
       //load post model
 
       $this->load->model('exhibitions_model');
 
       //per page limit
 
       $this->perPage 5;
 
   }
 
   
    public 
function index(){
 
       $data = array();
 
       
        
//get rows count
 
       $conditions['returnType'] = 'count';
 
       $totalRec $this->exhibitions_model->getRows($conditions);
 
       
        
//pagination config
 
       $config['base_url'   base_url().'pages/exhibitions/';
 
       $config['uri_segment'] = 3;
 
       $config['total_rows' $totalRec;
 
       $config['per_page'   $this->perPage;
 
       
        
//styling
 
       $config['num_tag_open'] = '<li>';
 
       $config['num_tag_close'] = '</li>';
 
       $config['cur_tag_open'] = '<li class="active"><a href="javascript:void(0);">';
 
       $config['cur_tag_close'] = '</a></li>';
 
       $config['next_link'] = 'Next';
 
       $config['prev_link'] = 'Prev';
 
       $config['next_tag_open'] = '<li class="pg-next">';
 
       $config['next_tag_close'] = '</li>';
 
       $config['prev_tag_open'] = '<li class="pg-prev">';
 
       $config['prev_tag_close'] = '</li>';
 
       $config['first_tag_open'] = '<li>';
 
       $config['first_tag_close'] = '</li>';
 
       $config['last_tag_open'] = '<li>';
 
       $config['last_tag_close'] = '</li>';
 
       
        
//initialize pagination library
 
       $this->pagination->initialize($config);
 
       
        
//define offset
 
       $page $this->uri->segment(3);
 
       $offset = !$page?0:$page;
 
       
        
//get rows
 
       $conditions['returnType'] = '';
 
       $conditions['start'] = $offset;
 
       $conditions['limit'] = $this->perPage;
 
       $data['omg_event'] = $this->exhibitions_model->getRows($conditions);
 
       
        
//load the list page view
 
       
       $this
->load->view('templates/header'$data);
 
     $this->load->view('pages/exhibitions'$data);
 
      $this->load->view('templates/footer');
 
   }
 
   


My model : 

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Exhibitions_model extends CI_Model{
 
   /*
     * Get posts
     */
 
   function getRows($params = array()){
 
       $this->db->select('*');
 
       $this->db->from('omg_event');
 
       if(array_key_exists("event_id",$params)){
 
           $this->db->where('event_id',$params['event_id']);
 
           $query $this->db->get();
 
           $result $query->row_array();
 
       }else{
 
           //set start and limit
 
           if(array_key_exists("start",$params) && array_key_exists("limit",$params)){
 
               $this->db->limit($params['limit'],$params['start']);
 
           }elseif(!array_key_exists("start",$params) && array_key_exists("limit",$params)){
 
               $this->db->limit($params['limit']);
 
           }
 
           
            if
(array_key_exists("returnType",$params) && $params['returnType'] == 'count'){
 
               $result $this->db->count_all_results();
 
           }else{
 
               $query $this->db->get();
 
               $result = ($query->num_rows() > 0)?$query->result_array():FALSE;
 
           }
 
       }

 
       //return fetched data
 
       return $result;
 
   }
}
?>

and my view page : 

PHP Code:
<head>
 
   <link href="<?php echo base_url() ?>css/about.css" rel="stylesheet">
</
head>

<!--==========================
 
   Intro Section
  
============================-->

 
 <section id="intro">
 
   <div class="intro-container">
 
     <div id="introCarousel" class="carousel  slide carousel-fade" data-ride="carousel">


 
       <div class="carousel-inner" role="listbox">

 
         <div class="carousel-item active">
 
            <div class="carousel-background"><img src="<?php echo base_url() ?>img/events.jpg" alt=""></div>
 
           <div class="carousel-container">
 
             <div class="carousel-content">
 
               <h2>Exhibitions</h2>
 
             </div>
 
           </div>
 
         </div>

 
     </div>
 
   </div>
 
 </section><!-- #intro -->

 
 <main id="main">

 
    
    
<!--==========================
 
     Team Section
    
============================-->
 
   <section id="team">
 
     <div class="container">
 
       <div class="section-header wow fadeInUp">
 
         

        
<div class="album py-5 bg-light">
 
   <div class="container">

 
      <div class="section-header">
 
         <h3>EXHIBITIONS ROADSHOWS SEMINAR</h3>
 
         <p></p>
 
       </div>

<
table class="table table-hover">
 
 <?php if(!empty($omg_event)): foreach($omg_event as $post): ?>
  <thead>
    <tr>
     

    </tr>
  </thead>
  <tbody>


    <tr>
      <th scope="row"><?php echo $post['name']; ?></th>
      <td width="10%"><?php echo $post['address']; ?></td>
      <td width="10%"><?php echo $post['name']; ?></td>
      <td></td>
      <td></td>
      <td width="15%""><a href="">Send Enquiry</a></td>
    </tr>
  <?php endforeach; else: ?>
                <tr><td colspan="3">Post(s) not found......</td></tr>
                <?php endif; ?>
  </tbody>
  
</table>
   <ul class="pagination pull-right">
    <?php echo $this->pagination->create_links(); ?>
</ul>    
      
      </div>

    </section><!-- #team -->


   
  </main> 



RE: Pagination not working - InsiteFX - 01-30-2019

Here is an example with download script.

Pagination In CodeIgniter With Example


RE: Pagination not working - firas - 01-30-2019

(01-30-2019, 09:40 AM)InsiteFX Wrote: Here is an example with download script.

Pagination In CodeIgniter With Example

I already try this, but I always stuck with base URL, every time I did it, it shows error 404 

my view page is in views/pages/exhibitions.php


RE: Pagination not working - InsiteFX - 01-31-2019

Your base url should point to controller/method

PHP Code:
$config['base_url'] = base_url('exhibitions/index'); 



RE: Pagination not working - firas - 01-31-2019

(01-31-2019, 04:41 AM)InsiteFX Wrote: Your base url should point to controller/method

PHP Code:
$config['base_url'] = base_url('exhibitions/index'); 

Already change it but when I click on the second page, it shows "Object Not  Found" and "Error 404".


RE: Pagination not working - firas - 02-06-2019

Can anyone help me?