如果我删除了第二个fetch_assoc,则列出所有团队可以正常工作。 但是,当我启动第二个fetch_assoc来填充团队经理时,我只是报错。我尝试了几种不同的方法,也都没有成功。
<?php
$query2 = "SELECT teams.* FROM teams WHERE teams_div = '1'";
$teams = $conn->query($query2);
if ($teams->num_rows > 0)
{
// output data of each row
while($roster = $teams->fetch_assoc())
{
?>
<div align="center" style="">
<img src="<?php echo $roster['teams_badge']; ?>" width="70" height="70">
<br/>
<b><?php echo $roster['teams_name']; ?></b>
<br/>
<form>
<input type="hidden" id="teams_id" name="teams_id" value="<?php echo $roster['teams_id']; ?>">
<input name="submit" id="submit" type="submit" value="Visit Team Profile">
</form>
</div>
<br/>
<br/>
<?php
$team = $roster['teams_id'];
$query3 = "SELECT users.* FROM users WHERE users_team = '$team' AND users_manager = '1'";
$manager = $query3->fetch_assoc();
?>
<b>Squad Manager: <?php echo $manager['users_username']; ?></b>
<?php
}
}
else
{
}
?>
预期结果 要列出每个团队及其经理,并且一旦可行,我也将列出每个团队中的所有球员。