遇到个很迷惘的问题
:( 在写1个博客,遇到个问题 就是首页分页问题,,代码如下:
$data['search_all'] = $this->article_model->get_all_page('',$title,$catid,'','','','','');
//分页
$total_rows=count($data['search_all']); //行数
//设定分页的根链接
$config = array();
$this->load->library('hpages');
//$config['base_url'] = site_url('welcome');
$config['base_url'] = "welcome/index"."?title=$title";
$config['total_rows'] = $total_rows; //总记录数
$config['per_page'] = 3; //每页显示记录数
$config['num_links'] = 3; //前面和后面的页面数
/*$config['prev_link'] = '上一页'; //上一页
$config['next_link'] = '下一页'; //下一页
$config['first_link'] = '首页'; //首页
$config['last_link'] = '末页'; //末页*/
$config['underline_uri_seg'] =1;
$this->hpages->init($config);
$data['page_str']=$this->hpages->create_links(1);
/**文章列表**/
$data['init_art'] = $this->article_model->get_all_page('',$title,$catid,'','','',$from_row,$config['per_page']);
$this->load->view('welcome',$data);
但是首页显示的是全部数据 并没有按设置的显示3条数据
:o首页显示的是全部数据 并没有按设置的显示3条数据,怎么样让它在首页就显示分页里面设置的显示3条数据, 要看你这个函数里面有没有limit数量啊,$this->article_model->get_all_page,CI分页是不会帮你把数据都选好的 我在MODEL里面有limit function get_all_page($catid,$title,$tag,$depict,$content,$from_row,$per_page){
if(!empty($catid)){
$sql_navigation="catid=".$catid;
}else{
$sql_navigation=1;
}
if (!empty($title)){
$sql_category="title=".$title;
}else{
$sql_category=1;
}
if (!empty($tag)){
$sql_category2="tag=".$tag;
}else{
$sql_category2=1;
}
if (!empty($depict)){
$sql_keyword="depict".$depict;
}else{
$sql_keyword=1;
}
if (!empty($content)){
$sql_content="content".$content;
}else{
$sql_content=1;
}
$from_row=$from_row?$from_row:'0';
if (!empty($per_page)){
$sql_limit="limit $from_row,$per_page";
}else{
$sql_limit="";
}
$sql = "SELECT * FROM articles WHERE ".$sql_navigation." and ".$sql_category." and ".$sql_category2." and ".$sql_content." and ".$sql_keyword." order by addtime desc,id asc $sql_limit";
//echo $sql;
$query = $this->db->query($sql);
$rows = array();
foreach ($query->result_array() as $key=>$row){
$rows[$key] = $row;
$CI = get_instance();
$CI->load->model('category_model');
$rows[$key]['category_arr']=$CI->category_model->get_one($rows[$key]['catid']);
$CI = get_instance();
$CI->load->model('user_model');
$rows[$key]['user_arr']=$CI->user_model->get_one($rows[$key]['uid']);
}
return $rows;
} 当点击了下一页后 分页才起了作用,一打开首页加载的是welcome这个首页,数据库并没有根据需要显示几条 本帖最后由 ahkxhyl 于 2011-2-5 12:07 编辑
这个一打开首页的sql语句:
SELECT * FROM articles WHERE 1 and 1 and 1 and 1 and 1 order by addtime desc,id asc
下面这个是点击分页页面后的sql语句(第2页):
SELECT * FROM articles WHERE 1 and 1 and 1 and 1 and 1 order by addtime desc,id asc limit 0,2
-----------------------------------------------------
点击分页 1 时 http://localhost/blog/welcome?title=&per_page=1 这样分页起了作用
默认一打开页面 http://localhost/isblog/welcome 分页不起作用 列出了 全部的数据
--------------------------------------------------------------------------------
我现在的意思是:让 http://localhost/isblog/welcome也有分页的效果 根据需要列出数据条数 对啊,第一页或者不指定页的时候都要按第一页来进行limit啊 现在就是这个问题,那能帮我看看 我上面的 哪里写错了。我这个一打开页面 就是没有按第一页来进行limit {:3_65:}继续求助..
页:
[1]
2