活动记录 - 找到3个结果,但只返回一个 [英] Active record - 3 results found, but only one being returned
问题描述
下面的查询返回3个结果可用,但它只返回一个条目id。
The query below is returning that 3 results are available, but it is only returning one entry id.
如何返回三个entry_id? >
How can I have the three entry_id's returned?
$this->EE->db->select('entry_id, count(portfolio_number) AS results');
$this->EE->db->from('submissions');
$this->EE->db->where('type_id', '1');
$this->EE->db->where('member_group', $member_group);
$this->EE->db->group_by('portfolio_number');
$this->EE->db->having('results = 3');
$query = $this->EE->db->get();
$submissions = $query->result_array();
print_r($submissions);
编辑:
列 entry_id
, member_group
, type_id
和 portfolio_number
。
portfolio_number列的数字介于1到7之间。
The portfolio_number column will have a number between 1 and 7.
我需要查询数据库中具有相同portfolio_number(以及匹配类型和member_id)的3行,并返回这三行中的每一行的entry_id。
I need to query the database for 3 rows that have the same portfolio_number (as well as matching type and member_id) and return the entry_id for each of those three rows.
推荐答案
您可以替换这段代码
$ this-> EE-> db-> group_by('portfolio_number'); //每个Portfolio_number只返回一行
$ this-> EE-> db-> group_by('portfolio_number,entry_id'); //将返回一行每个portfolio_number和entry_id
$this->EE->db->group_by('portfolio_number'); //It will return only one row per portfolio_number
$this->EE->db->group_by('portfolio_number,entry_id'); // It will return one row per portfolio_number and entry_id
我认为它会返回3行不同的entry_id
I think it will return 3 rows of different entry_id
这篇关于活动记录 - 找到3个结果,但只返回一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!