Active record - 3 results found, but only one being returned

后端 未结 3 2060
滥情空心
滥情空心 2021-01-28 15:14

The query below is returning that 3 results are available, but it is only returning one entry id.

How can I have the three entry_id\'s returned?

$this-&g         


        
相关标签:
3条回答
  • 2021-01-28 15:25

    Your $this->EE->db->group_by('portfolio_number'); is causing a single row with aggregated data to be returned.

    If you want all the ids to be returned as well, you can try adding

    $this->EE->db->select('GROUP_CONCAT(entry_id) AS entry_ids', false);
    

    and then splitting the entry_ids field in PHP:

    str_getcsv($submissions);
    

    Edit: I put in the second argument for the select query to prevent backticks being placed around the custom select query.

    0 讨论(0)
  • 2021-01-28 15:34

    You can handle it like this

    $results    =   $this->EE->db
                            ->select('entry_id')
                            ->from('submissions')
                            ->where('type_id', '1')
                            ->where('member_group', $member_group)
                            ->group_by('portfolio_number')
                            ->get()
                            ->result_array();
    
    if(count($results)){
        return $results
    }else {
        return false;
    }
    
    0 讨论(0)
  • 2021-01-28 15:37

    Can you please replace this code

    $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

    I think it will return 3 rows of different entry_id

    0 讨论(0)
提交回复
热议问题