我正在尝试根据当前登录的用户显示所有团队,并使用查询生成器显示每个团队中的成员以显示如下内容:
team logo | team name | member ign
image | dotatest3team_2 | dotafortest1
| dotafortest2
| dotafortest3
| dotafortest10
| dotafortest11
image | codtest2team | dotafortest1
| dotafortest2
| dotafortest3
| dotafortest10
| dotafortest11
不知何故,我得到了:
- 它只显示 1 个团队“codtest2team”
- 它显示 6 个成员(我认为它是从 add_game 表记录中提取的)而不是 5 个成员(来自 teammember_list 表)
以下是我当前的代码:
模型
return $this->db->table('team_list t1')
->join('teammember_list t2', 't2.team_id = t1.team_id')
->join('add_game t3', 't3.game_id = t2.game_id')
->join('game_list t4', 't4.game_id = t3.game_id')
->where('t2.user_id', $user_id)
->get()
->getResultArray();
看法
<table class="table teams-list">
<thead class="thead-light">
<tr>
<th scope="col">Logo</th>
<th scope="col">Team Name</th>
<th scope="col">Members IGN</th>
</tr>
</thead>
<tbody>
<?php
$team_array = array();
foreach ($teams as $row) {
// Set title value
$team = $row['team_id'];
// Check if team value has already been used, proceed if not
if(!in_array($team, $team_array)) {
// Add team value to $team_array and echo team
$team_array[] = $team;
?>
<tr>
<th scope="row"><img src="<?php echo base_url('/public/uploads/img/'. strtolower($row['team_logo'])); ?>" alt="" /></th>
<td><?= $row['team_name']; ?></td>
<td>
<?php
foreach ($teams as $row) {
if($team == $row['team_id']) {
?>
<?= $row['ign']; ?>
<?php
}
}
?>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
我找不到什么和哪里错了。谁可以帮我这个事?提前谢谢各位!