CodeIgniter Forums
Pagination not performing proparly - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Pagination not performing proparly (/thread-57337.html)



Pagination not performing proparly - El Forum - 03-07-2013

[eluser]ede196620[/eluser]
am working on a pagination for my website its first time i am trying to make this work the problem is that the pagination dose not turn pages when the number of the link is clicked. i very new to codeigniter and php and cant figure this out i tout this would be a great place to start to get some advice. Here is my code :

Controller

Code:
class Result_controller extends CI_Controller{
    
    function page($page_num=1){
        
        $results_per_page = 25;
        $this->load->model('result_model');
        $this->load->library('pagination');

        $config['base_url'] = 'http://localhost/Surva/index.php/result_controller/page/';
        $config['total_rows'] = $this->result_model->count_all();
        $config['per_page'] = $results_per_page;
        $config['use_page_numbers'] = TRUE
        $config['num_links'] = 10;
        $config['uri_segment'] = 3;
        $this->pagination->initialize($config);
        
        $data['records'] = $this->result_model->get_page($page_num, results_per_page);
        $data['pagination'] = $this->pagination->create_links();
        $this->load->view('result_view', $data);
    }
}

model

Code:
class Result_model extends CI_Model{
    
    function get_page($page_num=1, $results_per_page=25) {
        // Make sure we have a positive page number.
        if ($page_num < 1)
        {
            $page_num = 1;;
        }
        
        $this->db->select('tblanswers.*,credentials.*');
        $this->db->from('tblanswers');
        $this->db->join('credentials', 'tblanswers.answerid = credentials.cid', 'LEFT');
        $this->db->limit(($page_num - 1) * $results_per_page, $results_per_page);
        $query = $this->db->get();
        
        return $query->result_array();
    }
    
    function count_all()
    {
        $this->db->join('credentials', 'tblanswers.answerid = credentials.cid', 'LEFT');
        return $this->db->count_all('tblanswers);
    }
  
}


and my view

Code:
&lt;html&gt;
    &lt;head&gt;
     &lt;title&gt;Results&lt;/title&gt;

    &lt;/head&gt;
    &lt;body&gt;
        
        <center>
        
     <div>          
         <table border="1">
          <tr>
             <th>Name</th>
             <th>Second Name</th>
             <th>Phone</th>
             <th>Email</th>
             <th>Answer</th>
             <th>Comment</th>
            
         </tr>
          &lt;?php foreach ($query as $row): ?&gt;
         <tr>      
             <td>&lt;?php echo $row->name; ?&gt;</td>
             <td>&lt;?php echo $row->second_name; ?&gt;</td>
             <td>&lt;?php echo $row->phone; ?&gt;</td>
             <td>&lt;?php echo $row->email; ?&gt;</td>
              <td> &lt;?php echo $row->answerA;?&gt;
            &lt;?php echo $row->answerB;?&gt;
            &lt;?php echo $row->answerC;?&gt;</td>
             <td>&lt;?php echo $row->comment;?&gt;<br></td>    
            
         </tr>
        
          &lt;?php endforeach; ?&gt;
        
         </table>  
         &lt;?php if (isset($pagination))
          {
           echo $pagination;
          // echo "<pre>"; var_dump($query);
           }
          ?&gt;      
   </div>
        </center>
    &lt;?php echo anchor('http://localhost/Surva/index.php/home', 'Home'); ?&gt;
    &lt;/body&gt;
    &lt;/html&gt;



Pagination not performing proparly - El Forum - 03-08-2013

[eluser]Harold Villacorte[/eluser]
If the links are getting generated then the pagintation is working correctly. I don't see anywhere in your controller code where you are passing an array of objects called $query to the view. All I see is an array of arrays called $records.


Pagination not performing proparly - El Forum - 03-12-2013

[eluser]ede196620[/eluser]
tnx for the replay i fixed the problem.