0

I have a stored procedure which will grab team names along with the admin users of the team, or if the team does not have an admin, replace the user with N/A. The following is the stored procedure:

BEGIN
    SELECT teams.name,
            IFNULL(users.email,'N/A') as email,
            IFNULL(users.name,'N/A') as user_name,
            IFNULL(team_user.role,'N/A') as role
    FROM teams
        LEFT JOIN team_user ON teams.id=team_user.team_id
        LEFT JOIN users ON team_user.user_id=users.id
    WHERE role is NULL
    OR role='admin';
END

I would like to display the result of the stored procedure in a table. The following is an example of the table that it displays:

Team Name User Name
Team1 AdminUser1ForTeam1
Team1 AdminUser2ForTeam1
Team 2 AdminUser1ForTeam1
Team3 AdminUser1ForTeam3
Team3 AdminUser2ForTeam3

The problem with this table is that if a team has more than 1 admin, the team name will be repeated in two separate rows. The following is the result I want to achieve:

Team Name User Name
Team1 AdminUser1ForTeam1, AdminUser2ForTeam1
Team 2 AdminUser1ForTeam1
Team3 AdminUser1ForTeam3, AdminUser2ForTeam3

Here is the html/php code to draw the table

 <table class="table table-bordered">
    <tbody>
        @foreach($tester as $test)
        <tr>
            <td>{{$test->name}}</td>
            <td>{{$test->user_name}}</td>
            <td>{{$test->email}}</td>
        </tr>
        @endforeach
    </tbody>
</table>    

With $tester being the variable returned from the stored procedure. Any ideas on how I can achieve the second table, any help is greatly appreciated!

RiggsFolly
  • 89,708
  • 20
  • 100
  • 143
matthew-vidovic
  • 63
  • 1
  • 10

0 Answers0