多个表连接中的codeigniter分页显示错误为foreach()提供的无效参数

时间:2017-07-08 09:44:09

标签: php codeigniter-3

我有分页问题。当我点击下一个但它带来上述错误,但是当我点击上一个链接时它正常工作。这是我的控制器代码:

public function categoryfour()

{

$config = array();

    $config["base_url"] = base_url() . "bulletins/categoryfour";

    $total_row = $this->news_model->record_count_category_four();

    $config["total_rows"] = $total_row;

    $config["per_page"] = 2;

    $config["uri_segment"] = 3;

    $config['use_page_numbers'] = TRUE;


    $config['num_links'] = $total_row;

    $config['cur_tag_open'] = '&nbsp;<a class="current">';

    $config['cur_tag_close'] = '</a>';

    $config['next_link'] = 'Next';

    $config['prev_link'] = 'Previous';

    $this->pagination->initialize($config);
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data["posts"] =$this->news_model->get_news_cat_four($config["per_page"], $page);

    $str_links = $this->pagination->create_links();

    $data["pages"] = explode('&nbsp;',$str_links );

    $this->load->view('category_one',$data);
}

这是模型的代码:

function get_news_cat_four($limit, $start)
{

    $this->db->select('news.id as newsId,news_category.id as catId,users.id as userId,news.*,news_category.*,users.*,comments.*, COUNT(comments.post_id) as num_comments');

    $this->db->join('users' , 'users.id = news.user_id');

    $this->db->join('news_category' , 'news_category.cat_id = news.news_id');

    $this->db->join('comments' , 'comments.post_id = news.id');

    $this->db->group_by('comments.post_id');

    $this->db->order_by('news.date_added','desc');

    $this->db->where('news.news_id',4);

    $this->db->limit($limit, $start);

    $query = $this->db->get("news");

    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;}

最后是观点:

<div id="page-content" class="single-page container">

    <div class="gutter-7px">

        <div id="main-content" class="col-md-8 fix-right">

            <article class="single-post">

            <?php if(count($posts)) { 

              foreach($posts as $n){ ?>

                <div class="entry-header">

                    <h1 class="entry-title"><a href="<?php echo base_url('bulletins/view/'.$n->newsId)?>"><?php echo $n->title;?></a></h1>
                    <span> <i class="fa fa-calendar"></i> <?php echo date( 'F jS, Y g:i a' , strtotime($n->date_added))?>/ 

               <i class="fa fa-comment-o"></i>

               <?php echo $n->num_comments;?>/<i class="fa fa-user"></i> 

                   <?php echo $n->username?></span>

                </div>
                <div class="post-thumbnail-wrap"><a href="<?php echo base_url();?>bulletins/view/<?php echo $n->newsId?>"><img src="<?php echo base_url('assets/images/'.$n->image)?>"
                 style="width:800px;height:500px" /></a></div>

                <div class="entry-content">
                            <p><?php echo  substr(strip_tags($n->content), 0, 200).'...';?></p>
                            <a href="<?php echo base_url()?>bulletins/view/<?php echo $n->newsId?>">Read More...</a>
                            <?php }}?>
                            </div>

            </article>
            <div id="pagination">
             <ul class="pagination">

             <!-- Show pagination links -->
             <?php foreach ($pages as $link) {

              echo "<li>". $link."</li>";

               } 
              ?>

            </div>

    </div>
            </div>

0 个答案:

没有答案