【发布时间】:2015-09-26 15:13:39
【问题描述】:
我需要进行查询并获取某种数据。我有 2 个表、用户和连接,我需要获取每个用户每月和每年连接的次数。
users connections
........... ................
john 10/02/2014
john 15/02/2014
john 03/01/2015
john 06/02/2015
是否有机会以这种格式获取此信息:
john=>
[0]=>2014
[0]=>02
'total' =>2
[1]=>2015
[0]=>01
'total' => 1
[1]=>02
'total' => 2
[2]=>03
'total'=> 1
我正在使用 Codeigniter 和 PHP。
回答@CodeGodie 到目前为止我所做的是:
public function getPeriodicity(){
$this->db->select('u.vusr_user, extract (MONTH from (to_timestamp(c.vuc_log_in))) as month, extract (YEAR from (to_timestamp(c.vuc_log_in))) as yearly, COUNT(c.vuc_log_in)');
$this->db->from('vts_users_conn c');
$this->db->join('vts_users u', 'c.vuc_vusr_id = u.vusr_id');
$this->db->group_by('u.vusr_user, month, yearly','asc');
$query = $this->db->get();
return $query->result_array();
}
【问题讨论】:
-
@CodeGodie 我已经用我所做的编辑了帖子
标签: php mysql arrays codeigniter multidimensional-array