我尝试使用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'] = ' <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(' ',$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)
我正在使用这样的东西来获得你想要的结果(这里没有使用你的代码):
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;
}