我有两个php循环,一个有CPU选择选项,它也有套接字变量。第二个是另一个用于主板选择选项的php循环,它也具有socket var。但是,如果你选择一个带有LGA1151插座的CPU,并且主板上有另一个不同的插座,那么我需要第二个环路(主板)更换为只显示与所选CPU相同插座的主板。依赖于第一个选择选项更改第二个选择选项
这里是我的代码为2循环
<li class="flip-container" style="z-index: 19;">
<div class="flipper default">
<div class="front">
<h2>CPU</h2>
</div>
<div class="back" style="height:auto;width:400px;padding:15px; ">
<script>
\t \t \t \t function cpuPreview(sel) {
\t \t \t \t \t document.getElementById('Imgcpu').src = "" + sel.options[sel.selectedIndex].id;
\t \t \t \t }
\t \t \t \t </script>
\t \t \t <div class="custom-select">
\t \t \t \t <label for="select-choice1" class="label select-1"><span class="selection-choice">Please choose something</span> </label>
\t \t \t \t <select id="cpu" name="cpu" class="select" onChange="cpuPreview(this)" >
\t \t \t \t \t <option data-price="0">Please select 1</option>
\t \t \t \t \t <?php $psut = $con->query("SELECT * FROM parts WHERE type = 'cpu'");?>
\t \t \t \t \t \t <?php while($psu = $psut->fetch_object()): ?>
\t \t \t \t \t <option id="<?= $psu->image ?>" value="<?= $psu->id ?>" data-price="<?= $psu->price ?>"><?= $psu->name ?></option>
\t \t \t \t \t \t <?php endwhile;?>
\t \t \t \t \t </select>
\t \t \t \t </div>
\t \t \t \t \t <img id='Imgcpu' src="" width="300px" height="auto">
</div>
</div>
</li>
<li class="flip-container" style="z-index: 17;">
<div class="flipper default">
<div class="front">
<h2>Motherboard</h2>
</div>
<div class="back" style="height:auto;width:400px;padding:15px; ">
<script>
\t \t \t \t function motherboardPreview(sel) {
\t \t \t \t \t document.getElementById('Imgmotherboard').src = "" + sel.options[sel.selectedIndex].id;
\t \t \t \t }
\t \t \t \t </script>
\t \t \t <div class="custom-select">
\t \t \t \t <label for="select-choice1" class="label select-1"><span class="selection-choice">Please choose something</span> </label>
\t \t \t \t <select id="motherboard" name="motherboard" class="select" onChange="motherboardPreview(this)" >
\t \t \t \t \t <option data-price="0">Please select 1</option>
\t \t \t \t \t <?php $psut = $con->query("SELECT * FROM parts WHERE type = 'motherboard'");?>
\t \t \t \t \t \t <?php while($psu = $psut->fetch_object()): ?>
\t \t \t \t \t <option value="<?= $psu->id ?>" id="<?= $psu->image ?>" data-price="<?= $psu->price ?>"><?= $psu->name ?></option>
\t \t \t \t \t \t <?php endwhile;?>
\t \t \t \t \t </select>
\t \t \t \t </div>
\t \t \t \t \t <img id='Imgmotherboard' src="" width="300px" height="auto">
</div>
</div>
</li>
你需要使用AJAX功能来查询数据库,并填充第二个下拉菜单 – RamRaider
或者你可以把所有可能的值到第二下拉菜单,只显示你想要的人。 – BlobbyBob
[显示基于上一个下拉选择的第二个下拉菜单]的可能重复(https://stackoverflow.com/questions/6954556/show-a-second-dropdown-based-on-previous-dropdown-selection) –