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

[已解决] 想关一个关于数据库查询时间的问题

[复制链接]
发表于 2015-1-22 17:56:39 | 显示全部楼层 |阅读模式
我想查询数据库里面今天注册的用户总人数,数据库用户表是:user,注册时间字段:register_time弄了好久不知道怎么弄,谁知道的可以说下吗,非常感谢!!



发表于 2015-1-22 18:09:52 | 显示全部楼层
本帖最后由 Closer 于 2015-1-22 18:19 编辑

手冊裡有提到 CI 手冊 - Active Record 类
有一區塊在介紹 $this->db->where();
你試試這個下面那兩段代碼

PHP复制代码
 
//控制器
$table = 'user';
$th_s = 'register_time >';
$td_s = date('Y-m-d').' 00:00:00';
$th_e = 'register_time <';
$td_e = date('Y-m-d').' 23:59:59';
 
$today_count = $this->(你模型的名稱)->get_Today_ppl($table, $th_s, $td_s, $th_e, $td_e);
 
复制代码


PHP复制代码
 
//模型
public function get_Today_ppl($table, $th_s, $td_s, $th_e, $td_e){
        $query = $this->db->where($th_s,$td_s)->where($th_e,$td_e)->get($table);
        return $query->num_rows();
}
 
复制代码
 楼主| 发表于 2015-1-22 18:26:22 | 显示全部楼层
Closer 发表于 2015-1-22 18:09
手冊裡有提到 CI 手冊 - Active Record 类
有一區塊在介紹 $this->db->where();
你試試這個下面那兩段代碼

试了下,不行呢,register_time在数据库表里是一串数字的,像这样:1395891819,不是平日的日期格式file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\412527025\QQ\WinTemp\RichOle\RVAND0RP}{8MRM3Z2{@]FA9.jpg,不过还是很感谢
发表于 2015-1-22 18:29:53 | 显示全部楼层
913057579 发表于 2015-1-22 18:26
试了下,不行呢,register_time在数据库表里是一串数字的,像这样:1395891819,不是平日的日期格式,不 ...

那你只要更換 $td_s & $td_e 就好
你得先找出它的規律

本版积分规则