我在我的codeigniter项目中保留了分页。链接都显示在视图页面中。但无论我点击哪个链接,都会让我进入同一页面...... 以下是我的控制器代码..
public function newsletter()
{
$this->load->library('pagination');
$config = array();
$config["base_url"] = base_url() . "index.php/welcome/newsletter";
$this->load->model('newsletter_model');
$total_row = $this->newsletter_model->record_count();
$config["total_rows"] = $total_row;
$config["per_page"] = 1;
$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);
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}
else{
$page = 1;
}
$this->load->model('newsletter_model');
$data["results"] = $this->newsletter_model->fetch_data($config["per_page"], $page);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ',$str_links );
$this->load->model('newsletter_model');
$data['rm_newsletter'] = $this->newsletter_model->get_rm_newsletter();
$this->load->view('newsletter/newsletter',$data);
}
以下是我的观看代码:
foreach ($lt_newsletter as $letter) {
echo $newsletter['nl_newsletter']; }
<div id="pagination">
<ul class="pagination">
<?php foreach ($links as $link)
{
echo "<li>". $link."</li>";
} ?>
</ul>
</div>
最后在我的模特中:
public function fetch_data($limit, $id)
{
$this->db->limit($limit);
$this->db->where('nl_id', $id);
$query = $this->db->get("ins_newsletter");
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
}
}
}
public function record_count()
{
return $this->db->count_all("ins_newsletter");
}
public function get_rm_newsletter()
{
$data = $this->db->query('SELECT nl.* FROM ins_newsletter nl ORDER BY nl.nl_id DESC');
return $data->result_array();
}
在我的浏览器中,所有链接(1,2,3,4)都清晰显示,但在点击每个链接(1,2,3,4)后,它显示的是包含所有记录的同一页面。目前,我的数据库中有4条记录,它列出了所有记录。请指出我哪里出错......!在此先感谢。
答案 0 :(得分:0)
也许错误出现在你的模型中,我看到你有一个
$ this-&gt; db-&gt; where('nl_id',$ id);
但是在控制器的功能中你传递了两个参数
$ data [“results”] = $ this-&gt; newsletter_model-&gt; fetch_data($ config [“per_page”],$ page);
这是分页值,一个是记录数量,(不是变量),另一个是你传递的页面(1,2,3等)
因此,您必须添加另一个参数才能生成where
。看到这个link in pagination does not work如果你有其他问题可以告诉我。