|
楼主 |
发表于 2009-4-18 10:35:08
|
显示全部楼层
本帖最后由 yinzhili 于 2009-4-18 10:39 编辑
出现了新的问题,生成的导航页码链接不对,比如说生成的导航页码是这样的:
,当显示第二页的时候结果是正确的,但链接错位了。
比如说 http://localhost:8080/category/show/4/2 这是第二页的URL,然而单击第三页的链接"3"的时候却跳转到了http://localhost:8080/category/show/4/4 ,单击“上一页”时跳转到了 http://localhost:8080/category/show/4/ ,整个就乱了套了。
附上相关代码:
//这是控制器里的相关代码
$cate_id=$this->uri->segment(3);
$this->load->library('pagination');
$config['base_url'] = base_url().'category/show/'.$cate_id.'/';
$config['total_rows'] = $this->book_model->count_rows($cate_id); //count_rows函数会返回结果的总行数
$config['per_page'] = '2';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$config['uri_segment'] = 4;
$config['first_link'] = '首页';
$config['last_link'] = '末页';
$config['next_link'] = '下一页';
$config['prev_link'] = '上一页';
$config['cur_tag_open'] = "<font color='Red'><b>";
$config['cur_tag_close'] = "</b></font>";
$this->pagination->initialize($config);
$data['book_list'] = $this->book_model->get_category_detail($cate_id,$config['per_page'],$this->uri->segment(4));
$this->load->view('category_view',$data);
//这是模型里的相关代码
function count_rows($category_id){
$query_string="SELECT * FROM books,categories WHERE books.category=categories.cate_name AND categories.cate_id='{$category_id}'";
$query = $this->db->query($query_string);
if(($query->num_rows())!=0){
return $query->num_rows();
}
}
function get_category_detail($category,$num,$offset){
$query_string="SELECT * FROM books,categories WHERE books.category=categories.cate_name AND categories.cate_id={$category} LIMIT {$offset},{$num}";
$query = $this->db->query($query_string);
if( ($query->row_array())==null ){
return null;
}
else{
$result=$query->result();
return $result;
}
} |
|