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

[讨论/交流] 根据条件取总数。简单方法

[复制链接]
发表于 2010-6-25 13:57:24 | 显示全部楼层 |阅读模式
PHP复制代码
public function get_list_all($id){ //ID为分类的ID
                        $search  = post('search');  //取按钮值
                        $title   = post('title');
                        $leixing = post('leixing');
                        $tuijian = post('tuijian');
                       
                        $where = array('`c_small`'=>$id);  //初始化条件,如果没有搜索的话默认去当前分类下的总数
                        if(!empty($search)){//当按下搜索时,根据条件组合搜索条件
                                if(!empty($title)){$where = array_merge($where,array('`c_title` like'=>"%".$title."%"));}
                                if($leixing != "nothing"){$where = array_merge($where,array('`c_leixing`'=>$leixing));}
                                if($tuijian != "nothing"){$where = array_merge($where,array('`c_tuijian`'=>$tuijian));}
                        }
                        $this->db->where($where);
                        $this->db->from('`my_content`');
                        return $this->db->count_all_results();
                }
复制代码


很菜,不要骂,呵呵
发表于 2010-6-25 18:49:56 | 显示全部楼层
本帖最后由 上善若水 于 2010-6-25 18:50 编辑

没看太明白...............

是说你自定义函数 还是 count_all_results();

我一般的做法是将 where 部分单提出来 做一个函数

因为一般取总数是为了 做分页,必然有一个和它一样 where 的内容列表页
发表于 2010-6-25 18:53:19 | 显示全部楼层
AR不用加反引号的说,另AR有专门的->db->like()

本版积分规则