由于某种原因,分页不起作用

时间:2013-03-08 07:19:24

标签: php codeigniter pagination

我为我的项目制作了一个分页功能,但它不适用于e sime因为分页本身没有显示而且表中的数据没有返回它返回epmpty数组给我看看告诉我你是否看到任何东西错。

控制器

class Result_controller extends CI_Controller{

    function getall($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/getall';
        $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['query'] = $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){

         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');
    }

}

?>

查看

 <?php foreach ($query as $row): ?> 
         <tr>      
             <td><?php echo $row->name; ?></td>
             <td><?php echo $row->second_name; ?></td>
             <td><?php echo $row->phone; ?></td>
             <td><?php echo $row->email; ?></td>
              <td> <?php echo $row->aA;?>
               <?php echo $row->aB;?>
               <?php echo $row->aC;?></td>
             <td><?php echo $row->c;?><br></td>     

         </tr>

          <?php endforeach; ?>

         </table>  
         <?php if (isset($pagination))
          {
           echo $pagination;
           echo "<pre>"; var_dump($query);
           } 
          ?>    

页面剂量在每个页面上返回一个数组我收到错误: 严重性:注意

消息:尝试获取非对象的属性

文件名:views / result_view.php

0 个答案:

没有答案