CodeIgniter Forums
How to Group data with same id in a join query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to Group data with same id in a join query (/showthread.php?tid=80329)



How to Group data with same id in a join query - devprecious - 10-18-2021

Hello, please i have this in my controller
$pollModel = new Poll();
$polls = $pollModel->join('options', 'options.poll_id = polls.poll_id')->findAll();
if i loop through this it works but the problem is i have an option with same poll_id that  is more than one.. so it loop them differently instead of making them one..
i also tried to use groupBy()
$polls = $pollModel->join('options', 'options.poll_id = polls.poll_id')->groupBy('options.poll_id').findAll();
this is close to the answer but it only return just one option like if i have three option with same poll_id it only returns the first one..
Any help??