用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4933|回复: 15
收起左侧

[HELP] 遇到个很迷惘的问题

[复制链接]
发表于 2011-2-5 11:12:32 | 显示全部楼层 |阅读模式
在写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条数据

这个是首页截取的部分的图片

这个是首页截取的部分的图片
 楼主| 发表于 2011-2-5 11:26:36 | 显示全部楼层
首页显示的是全部数据 并没有按设置的显示3条数据,怎么样让它在首页就显示分页里面设置的显示3条数据,
发表于 2011-2-5 11:54:01 | 显示全部楼层
要看你这个函数里面有没有limit数量啊,$this->article_model->get_all_page,CI分页是不会帮你把数据都选好的
 楼主| 发表于 2011-2-5 11:57:23 | 显示全部楼层
我在MODEL里面有limit
 楼主| 发表于 2011-2-5 11:58:07 | 显示全部楼层
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;
    }
 楼主| 发表于 2011-2-5 12:00:51 | 显示全部楼层
当点击了下一页后 分页才起了作用,一打开首页加载的是welcome这个首页,数据库并没有根据需要显示几条
 楼主| 发表于 2011-2-5 12:02:59 | 显示全部楼层
本帖最后由 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也有分页的效果 根据需要列出数据条数
发表于 2011-2-5 12:11:53 | 显示全部楼层
对啊,第一页或者不指定页的时候都要按第一页来进行limit啊
 楼主| 发表于 2011-2-5 12:16:37 | 显示全部楼层
现在就是这个问题,那能帮我看看 我上面的 哪里写错了。我这个一打开页面 就是没有按第一页来进行limit
 楼主| 发表于 2011-2-5 13:28:28 | 显示全部楼层
继续求助..

本版积分规则