Welcome Guest, Not a member yet? Register   Sign In
Pagination not performing proparly
#1

[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;


Messages In This Thread
Pagination not performing proparly - by El Forum - 03-07-2013, 05:17 AM
Pagination not performing proparly - by El Forum - 03-08-2013, 01:29 PM
Pagination not performing proparly - by El Forum - 03-12-2013, 12:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB