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

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 :


class Result_controller extends CI_Controller{
    function page($page_num=1){
        $results_per_page = 25;

        $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;
        $data['records'] = $this->result_model->get_page($page_num, results_per_page);
        $data['pagination'] = $this->pagination->create_links();
        $this->load->view('result_view', $data);


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


         <table border="1">
             <th>Second Name</th>
          &lt;?php foreach ($query as $row): ?&gt;
             <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>    
          &lt;?php endforeach; ?&gt;
         &lt;?php if (isset($pagination))
           echo $pagination;
          // echo "<pre>"; var_dump($query);
    &lt;?php echo anchor('http://localhost/Surva/index.php/home', 'Home'); ?&gt;

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

tnx for the replay i fixed the problem.

Theme © iAndrew 2016 - Forum software by © MyBB