Ich habe zwei php-Schleifen, eine hat die CPU Optionen auswählen, es hat auch die Steckdose var. Die zweite ist eine andere PHP-Schleife für ein Motherboard wählen Sie Optionen, die auch die Steckdose var hat. Wenn Sie jedoch eine CPU mit Sockel LGA1151 wählen und das Motherboard einen anderen Sockel hat, muss ich die 2. Schleife (Motherboard) ändern, um nur Motherboards mit dem Sockel anzuzeigen, der der gewählten CPU entspricht.Ändern zweite Auswahloptionen abhängig von den ersten Auswahloptionen
Hier ist mein Code für die 2-Schleifen
<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>
Sie benötigen eine Ajax-Funktion verwenden, um die Datenbank abzufragen und das zweite Dropdown-Menü – RamRaider
füllen Sie können auch alle möglichen Werte in der zweiten Dropdown-Menü setzen und zeigen nur die, die Sie wünschen. – BlobbyBob
Mögliches Duplikat von [Zeige eine zweite Dropdown-Liste basierend auf der vorherigen Dropdown-Auswahl] (https://stackoverflow.com/questions/6954556/show-a-second-dropdown-based-on-previous-dropdown-selection) –