913057579 发表于 2015-1-22 17:56:39

想关一个关于数据库查询时间的问题

我想查询数据库里面今天注册的用户总人数,数据库用户表是:user,注册时间字段:register_time弄了好久不知道怎么弄,谁知道的可以说下吗,非常感谢!!



Closer 发表于 2015-1-22 18:09:52

本帖最后由 Closer 于 2015-1-22 18:19 编辑

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

//控制器
$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);

static/image/hrline/line3.png

//模型
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();
}

913057579 发表于 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,不过还是很感谢

Closer 发表于 2015-1-22 18:29:53

913057579 发表于 2015-1-22 18:26
试了下,不行呢,register_time在数据库表里是一串数字的,像这样:1395891819,不是平日的日期格式,不 ...

那你只要更換 $td_s & $td_e 就好
你得先找出它的規律
页: [1]
查看完整版本: 想关一个关于数据库查询时间的问题