我'm using codeigniter and I'我试图执行一个传递一个where子句的查询执行,这个 where
是一个数组,这是我的代码:
$now = date('Y-m-d H:i:s');
$this->record_model->getAllRecord(array('guid' => $guid,
'end_datetime <' => $now,
'GROUP BY hash'));
这是 getAllRecord
的内容
$query = $this->db
->select('*')
->from('appointments')
->where($where_clause) 'is passed as parameter..
->get()->result_array();
这是 where
的内容
array(3) {
["guid"]=>
string(36) "c3682d6f-75b2-4686-966d-cb3c9344369b"
["end_datetime <"]=>
string(19) "2016-01-21 12:03:58"
[0]=>
string(13) "GROUP BY hash"
}
现在,如果我删除所有工作良好的组,但如果我在结果中插入 Group By hash
for not have(duplicate),则会出现此错误:
在非对象上调用成员函数result_array()
基本上我想获取所有记录的信息,但是一些记录具有相同的哈希值,因此GROUP BY应该将该记录加入到一个记录中 . 但是我做错了什么......
2 回答
Group by不是where子句的一部分,因此codeigniter将生成语法错误的代码,因此
->get()
调用会生成正确的结果集 . 您应该使用单独的->group_by(...)
调用来添加group by子句 .试试这个