我想问一些关于我的代码的问题。在 MySQL 数据库中,有两个表,即表'Team'和表'Borrower'。
下面是表“团队”的图像
下面是表“借款人”的图像
在 PHP 页面,用户可以编辑任何用户的详细信息,包括他们的团队。从上表中可以看出,Namron team_id 为 3,即团队“燃烧器”。但是在页面上,我想如何在团队选择选项中显示,将列出所有在“团队”表中具有但选择为“燃烧器”的团队,因为这是 Namron 的当前团队。
以下是我当前的代码。
借款人详细信息.php
<?php
$badgeid = $_POST['badgeid'];
$sql = "SELECT *
FROM ets_borrower
INNER JOIN ets_team ON ets_borrower.team_id = ets_team.team_id
WHERE ets_borrower.status_id = 1
AND ets_borrower.badgeid = :badgeid
ORDER BY ets_borrower.fullname ASC";
$query = $conn->prepare($sql);
$query->execute(array(':badgeid' => $badgeid));
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$badgeid = $row["badgeid"];
$fullname = $row["fullname"];
$team_id = $row["team_id"];
$team_name = $row["team_name"];
}
$sql2 = "SELECT * FROM ets_team WHERE status = 1";
$query2 = $conn->prepare($sql2);
$query2->execute();
while($row2 = $query2->fetch(PDO::FETCH_ASSOC)){
$team_id2 = $row2["team_id"];
$team_name2 = $row2["team_name"];
?>
<div class="form-group row">
<div class="col-xs-3">
<label for="example-search-input">Badge ID</label>
</div>
<div class="col-xs-9">
<input class="form-control" type="text" name="badgeid" value="<?php echo $badgeid; ?>" readonly>
</div>
</div>
<div class="form-group row">
<div class="col-xs-3">
<label for="example-search-input">Name</label>
</div>
<div class="col-xs-9">
<input class="form-control" type="text" name="fullname" value="<?php echo strtoupper($fullname); ?>" readonly>
</div>
</div>
<div class="form-group row">
<div class="col-xs-3">
<label for="example-search-input">Team</label>
</div>
<div class="col-xs-9">
<select class="form-control" id="exampleFormControlSelect1" name="team_id">
<option value="<?php echo $team_id;?>" <?php echo $team_id2 == $team_id? 'selected': '';?> ><?php echo $team_name2;?></option>
</select>
</div>
</div>