Codeigniter 分页不';在点火器中不能工作

Codeigniter 分页不';在点火器中不能工作,codeigniter,pagination,Codeigniter,Pagination,我已经成功地在我正在使用的应用程序的某些页面上创建了分页,但我无法在这个页面上创建分页: 我在数据库里有7条记录,什么时候 页面显示所有7条记录,而不是我希望的5条 果不其然,不会显示分页的链接 这是我的控制器代码: public function displayAllFaqCategories() { //initializing & configuring paging $currentUser = $this->isLoggedI

我已经成功地在我正在使用的应用程序的某些页面上创建了分页,但我无法在这个页面上创建分页:

我在数据库里有7条记录,什么时候 页面显示所有7条记录,而不是我希望的5条

果不其然,不会显示分页的链接

这是我的控制器代码:

public function displayAllFaqCategories()
    {

         //initializing & configuring paging

        $currentUser = $this->isLoggedIn();
        $this->load->model('faqCategoriesModel');
        $this->db->order_by('sorder');
        $limit = 5;
        $offset = 3;

        $offset = $this->uri->segment(3);
        $this->db->limit(5, $offset);

        $data['faq_categories'] = $this->faqCategoriesModel->selectCategoriesAndParents();
        $totalresults = $this->db->get('faq_categories')->num_rows();

        //initializing & configuring paging
        $this->load->library('pagination');
        $config['base_url'] = site_url('/backOfficeUsers/faqcategories');
        $config['total_rows'] = $totalresults;
        $config['per_page'] = 5;
        $config['uri_segment'] = 3;


        $this->pagination->initialize($config); 

        $errorMessage = '';
        $data['main_content'] = 'faq/faqcategories';
        $data['title'] = 'FAQ Categories';

        $this->load->vars($data,$errorMessage);
        $this->load->vars($currentUser);
        $this->load->view('backOffice/template');

    } // end of function displayAllFaqCategories
这是我的模型功能代码:

public function selectCategoriesAndParents($selectWhat = array())
   {    
       $data = array();
       $query = $this->db->query("SELECT fq . * , COALESCE( fqp.$this->parent_name,  '0' ) AS parentname
                                  FROM $this->table_name AS fq
                                  LEFT OUTER JOIN $this->table_name AS fqp ON fqp.catid = fq.parentid"); 
       if($query->num_rows() > 0) 
       {
           foreach($query->result_array() as $row) 
               {
                   $data[] = $row;  
               }
           }           
       $query->free_result();
       return $data;
   } // end of function selectCategoriesAndParents    
在视图中,包含记录的表的下面有以下代码:

 <?php echo $this->pagination->create_links();?>

任何帮助都将不胜感激

你好,佐兰

像这样编辑

$offset = $this->uri->segment(3) ? $this->uri->segment(3) : 0;

我想你把两种不同的东西混在一起了。您正在部分使用CI的ActiveRecord类,但随后自己运行查询

最简单的改变是:

    // get all the rows
    $data['faq_categories'] = $this->faqCategoriesModel->selectCategoriesAndParents();
    // figure out the count of all of them
    $totalresults = count($data['faq_categories']);
    // only take some of the rows of the array, instead of keeping all of them and then showing all 7 of your records
    $data['faq_categories'] = array_splice($data['faq_categories'], $offset, $limit);
希望这能解决它

为了进一步解释最初的问题是什么,我认为当您运行此程序时:

$totalresults = $this->db->get('faq_categories')->num_rows();

它采用上一行
$this->db->limit(5,$offset)计入帐户,因此它只返回5行。然后,当您告诉分页库您只希望每页显示5个时,该库认为它实际上显示了所有结果,因此不需要分页链接

我更改代码如下://$offset=$this->uri->segment(3)$偏移量=$this->uri->段(3)$此->uri->段(3):0;结果保持不变,显示所有7条记录,没有分页链接…否..wat是$Totalpages的值。。??