我在网站上使用分页,但问题是它没有连续显示行号。
在我的网页中,我每页显示10行。单击下一页,它将再次显示1的行号。实际上它应该从页面中的11开始,但它再次显示为1。
控制器:
function index()
{
$config = array();
$config["base_url"] = base_url("index.php/blogs/index");
$config["total_rows"] = $this->blogs_model->record_count();
$config["per_page"] = 11;
$config['num_links'] = 20;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['records'] = $this->blogs_model->get_blogs($config["per_page"], $page);
$data['comments'] = $this->blogs_model->getcommentscount($this->uri->segment(3));
$data["links"] = $this->pagination->create_links();
$data['mainpage'] = 'blogs';
$data['mode'] = 'all';
$this->load->view('templates/template', $data);
}
型号:
function get_blogs($limit, $start)
{
$this->db->limit($limit, $start);
$this->db->Select('blogs.*');
$this->db->From('blogs');
$this->db->where(array('blogs.status' => 1));
$this->db->order_by("date", "desc");
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q->result();
} else {
return false;
}
}
答案 0 :(得分:1)
一切似乎都很好。您可以像这样更改Model
的功能。
function get_blogs($limit, $start) {
$this->db->select('*');
$this->db->from('blogs');
$this->db->where('status', 1);
$this->db->order_by("date", "DESC");
$this->db->limit($limit, $start);
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q->result();
} else {
return false;
}
}
答案 1 :(得分:1)
完成一些更改以查看其工作正常。这是在点击分页链接后正确显示s.no的最新代码。
<?php if(count($records) > 0) { ?>
<table>
<thead>
<tr>
<th scope="col">S.No</th>
<th scope="col">Blog Title</th>
</tr>
</thead>
<tbody>
<?php $i = $this->uri->segment(3)+0; foreach ($records as $row){ $i++; ?>
<tr>
<td class="align-center"><?php echo $i;?></td>
<td><?php echo $row->blog_title;?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="pagination"><?php echo $this->pagination->create_links(); ?></div>