Codeigniter 4 display records using join with multiple tables - 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: Codeigniter 4 display records using join with multiple tables (/showthread.php?tid=77591) |
Codeigniter 4 display records using join with multiple tables - Dr3am3rz - 09-21-2020 I am trying to display a team list with the list of members associated with their respective teams but I can't seem to get it working. I keep getting duplicates or displaying separate members for the same team. My current code is as below: I have insert my current database into [color=var(--blue-700)]sql fiddle[/color] [color=var(--blue-700)]Model[/color] Code: return $this->db->table('team_list t1') [color=var(--blue-700)]Controller[/color] Code: $db = db_connect(); [color=var(--blue-700)]View[/color] Code: <table class="table teams-list"> If the current logged in username is test3, I want it to display like :
Code: team logo | team name | game | leader ign | member ign | edit [color=var(--blue-700)]Hope someone can help me here. Thanks in advance guys![/color] RE: Codeigniter 4 display records using join with multiple tables - ojmichael - 09-21-2020 You have a few options here.. recursive SQL (slow), some hideous GROUP_CONCAT or a better proposed solution below. PHP Code: $teams = $this->db->table('team_list t1') Then you can loop through your teams for the table rows, and in the member column you can loop through the $team['members'] RE: Codeigniter 4 display records using join with multiple tables - Dr3am3rz - 09-22-2020 (09-21-2020, 11:39 PM)ojmichael Wrote: You have a few options here.. recursive SQL (slow), some hideous GROUP_CONCAT or a better proposed solution below. Hi, thank you so much for your help! But how do I do that? Do I return teams? or do I return teamIds? Sorry I am new to this and I still don't know how all these works. |