2017-07-10 3 views
0

codeigniterを使用して複数のテーブルジョインにページネーションを挿入しようとしましたが、すべてが無駄になりました。私は最初のリンクのみを取得でき、他のリンクは空のページを表示します。ここでcodeigniterのテーブルジョインでページ番号をつけることが可能です

はコードです:

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

よく質問すると、クエリにパラメータを渡すだけです(クエリ文字列を使用) –

+0

$ pager ['suffix'] = '&'というパラメータを追加します。 $ filters;ここで$ filtersは渡すパラメータ(文字列)です –

+0

親切に例を挙げてください – vinn

答えて

0

私はあなたが結果を得るために、このようなものを使用していますシークする(あなたのコードはここで使用していません):

listOrders($ordering) { 

     $this->load->library('pagination'); 

     $this->load->model('orders_model','orders'); 
     $this->orders->setLimit(DEFAULT_LIMIT); 
     $numRows = $this->orders->countOrders(); 
     $offset = ($this->uri->segment(4) != '' ? $this->uri->segment(4): 0); 
     $orderList = $this->orders->getOrderList($ordering,$offset); 

     $config['base_url'] = base_url().'/'.$this->language."/recent-orders/".$ordering."/"; 
     $config['per_page'] = DEFAULT_LIMIT; 
     $config['uri_segment'] = 4; 
     $config['num_links'] = 4; 
     $config['total_rows'] = $numRows; 

     $config['cur_tag_open'] = '<li class="active"><a href="#">'; 
     $config['cur_tag_close'] = '</a></li>'; 
     $config['num_tag_open'] = $config['next_tag_open'] = $config['prev_tag_open'] = $config['last_tag_open'] = $config['first_tag_open'] = '<li>'; 
     $config['num_tag_close'] = $config['next_tag_close'] = $config['prev_tag_close'] = $config['last_tag_close'] = $config['first_tag_close'] = '</li>'; 

     $this->pagination->initialize($config); 
     $data['paging'] = $this->pagination->create_links(); 
     if($data['paging']!= '') { 
      $data['paging_caption'] = formatPaginationCaption($this->pagination).$numRows; 
     } 

     $data['sortby'] = $ordering; 
     $data['offset'] = $offset;    
    } 
+0

ありがとうございます。私はあなたのモデルを見ていない。とにかく、私のコードからどんな種類の異常も検出することができますか? – vinn

関連する問題