Reputation: 37
Basically I am trying to achieve the same as stated on the link below db field(GROUP_CONCAT) as array
The reason why I am writing regarding similar question is because all the answers related to I can find related to group_concat that applies to my case are from 2011, 2012. So I am not sure if that is the best solution now days.
I have created so far this
$sql->select( array('a.id', 'a.user_id', 'a.title', 'a.created', 'a.published', 'b.title AS obtitle', 'b.items_id'))
->from($this->db->quoteName('table1', 'a'))
->join('LEFT', $this->db->quoteName('table2', 'b'). '
ON (' .$this->db->quoteName('a.id').'='.$this->db->quoteName('b.items_id').')')
->where($this->db->quoteName('a.user_id') . ' =' . $this->db->quote($userid).' AND ' .$this->db->quoteName('a.published') . ' = 1')
->group($this->db->quoteName('b.item_id'));
$query = $this->db->setQuery($sql);
My question, is it still right to use group_concat? Or is it old practice (hence why I only find old answers)? would PDO::FETCH_ASSOC be more appropriate for merging the results that have a common id into an array and sub array?
Upvotes: 0
Views: 772
Reputation: 157916
There is nothing wrong with group_concat, yet PDO::FETCH_ASSOC offer not a slightest help in grouping anything.
Upvotes: 1