|
最近因为项目的关系,一定得用分页,CI内建分页类,就是我用起来常常有问题...
第一页,很正常没问题
第二页,突然变成十个结果...
第三页,十三个...{:soso_e153:}
第四页,八个...{:soso_e141:}
第五页,三个,而且还跟第四页的重复...{:soso_e109:}
Contrller::
PHP复制代码
public function myQuestion ($page=0)
{
$this->load->library('session');
$data['user_name']=$this->session->userdata('user_name');
if(@$data['user_name']!=null){
$data['board_name']=$this->data_title_real;
$data['realname']=$this->data_title_index;
$data['title']=$this->data_title_myq;
$data['description']=$this->data_description;
$data['more']=$this->data_more;
$this->load->model('Question_model');
$this->load->database();
$this->load->library('pagination');
$config['base_url'] = '/index.php/question/myQuestion/';
$config['total_rows'] = $this->Question_model->count_my_questions($data['user_name']);
$config['per_page'] = 5;
$config['first_link'] = '«第一頁';
$config['last_link'] = '最後一頁»';
$config['full_tag_open'] = '<li>';
$config['full_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li><a>';
$config['cur_tag_close'] = '</li></a>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['next_link'] = '下一頁»';
$config['prev_link'] = '«上一頁';
if(isset($page))
{
}else {
$page=0;
}
if(!is_numeric($page)){
exit;
}
$data['mine']=$this->Question_model->my_questions($data['user_name'],$page,$page+5);
if(!isset($data['mine'])){
exit;
}
$this->pagination->initialize($config);
$data['pagelink'] = $this->pagination->create_links();
if($this->Question_model->count_my_questions($data['user_name']) >= 1){
$this->load->view('header_view',$data);
$this->load->view('myQuestion_view',$data);
$this->load->view('footer_view');
} else {
$data['board_name']=$this->data_title_real;
$data['realname']=$this->data_title_index;
$data['title']=$this->data_title_success;
$data['description']=$this->data_description;
$data['more']=$this->data_more;
$msg['success']=$this->data_msg_noq;
$msg['icon']='error.png';
$msg['urlto']=$this->msg_url_tos;
$this->load->view('header_view',$data);
$this->load->view('messageSuccess_view',$msg);
$this->load->view('footer_view');
}
} else {
$data['board_name']=$this->data_title_real;
$data['realname']=$this->data_title_index;
$data['title']=$this->data_title_success;
$data['description']=$this->data_description;
$data['more']=$this->data_more;
$msg['success']=$this->data_user_nologin;
$msg['icon']='error.png';
$msg['urlto']=$this->msg_url_to;
$this->load->view('header_view',$data);
$this->load->view('messageSuccess_view',$msg);
$this->load->view('footer_view');
}
}
复制代码
Model::
PHP复制代码
public function my_questions($uname,$page,$pages)
{
$query_my_question = $this->db->query("SELECT * FROM `pre_questions` WHERE `question_askuser` LIKE '$uname' order by `question_qid` desc LIMIT $page, $pages ");
if ($query_my_question->num_rows() > 0){
return $query_my_question;
}
}
复制代码
View::
HTML复制代码
<div class="container">
<div class="hero-unit">
<h1>我的问题 </h1>
<p>你好, <strong><?php echo $user_name; ?></strong>,底下是您的发问纪录,方便您找到您过去问过的问题。 </p>
<div class="well">
<?php foreach ($mine->result() as $m){ ?>
<?php if($m->question_closedate > date('Y-m-d')) { ?>
<li>
<?php if($m->question_isanswered!=0){ ?>
<span class="badge badge-success">已解决 </span> 
<?php } else { ?>
<span class="badge badge-important">未解决</span> 
<?php } ?>
<span class="badge badge-success">未到期</span> 
<a href="/index.php/question/view/<?php echo $m->question_qid; ?>"> <?php echo $m->question_title; ?> </a></li><br>
<?php } else { ?>
<li>
<?php if($m->question_isanswered!=0){ ?>
<span class="badge badge-success">已解决 </span> 
<?php } else { ?>
<span class="badge badge-important">未解决</span> 
<?php } ?>
<span class="badge badge-important">已到期</span> 
<a href="/index.php/question/view/<?php echo $m->question_qid; ?>"> <?php echo $m->question_title; ?> </a></li><br>
<?php } ?>
<?php } ?>
</div>
<div class="pagination">
<ul>
<?php echo $pagelink; ?>
</ul>
</div>
</div>
复制代码
真心蛋疼,求助{:soso_e134:} |
|