duanbiaoshu2021
2018-09-26 12:33
浏览 31
已采纳

在没有POST的情况下将数据从DB加载到下拉列表中

I have 2 dropdown select in a HTML modal, one is for teams and the other is for players.

Teams dropdown select data are extracted from a DB. Each player is assigned to a team.

What I'm trying to do is when I change the teams dropdown select, the players dropdown select change according to the selected team which means it will contain only the players of the selected team.

==> I want to do that without CLOSING the modal and without REFRESHING the page.

<select id="teams" name="teams">
 <?php
 $sql = $bdd->query('SELECT * FROM teams;');
 while($fetch = $sql->fetch(PDO::FETCH_ASSOC)){ ?>                      
   <option id="opt-<?php echo $fetch['id_team']; ?>"><?php echo $fetch['name']; ?></option>
 <?php } ?>
</select>

<select id="players" name="players">
 <?php
 $sql = $bdd->query('SELECT * FROM players where id_team=...;');
 while($fetch = $sql->fetch(PDO::FETCH_ASSOC)){ ?>                      
   <option id="opt-<?php echo $fetch['id_player']; ?>"><?php echo $fetch['name']; ?></option>
 <?php } ?>
</select>

How can this be done ?

2条回答 默认 最新

相关推荐 更多相似问题