Codeigniter 4 display records using join with multiple tables |
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]
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'] (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. |
Welcome Guest, Not a member yet? Register Sign In |