我想填充一個下拉框,基於從另一個下拉框中的選擇。以下是我對PHP代碼:填充下拉框,基於另一個下拉框使用php,mqsql和ajax的選擇
<form id="inventory" method="POST" action="">
<fieldset>
<label for="area" >Select Shelf Area</label>
<select id="area" name="area">
<option value=""></option>
<?php $area = $conn->query("
select substring_index(location, ' ', 1) as area
FROM location GROUP BY substring_index(location, ' ', 1)");
while ($row = $area->fetch_assoc()) {
echo '<option value="' . $row['area'] . '" >' . $row['area'] . '</option>';
}
>
</select><br/>
</fieldset>
</form>
當我運行我的查詢,一切都很好,但我需要利用這個結果,並用它來填充另一個下拉框(從<「值以前下拉'>)這裏是:
echo "<label for='location' id='label'>Select location:</label>";
echo "<select id='location' name='location'>";
echo "<option value=''>--Select Location--</option>";
$query = "SELECT location_id, location FROM location
WHERE location LIKE '<value from previous drop down box>'
ORDER BY location";
$result = $conn->query($query);
while ($row = $result->fetch_assoc()) {
echo '<option value="' . $row['location'] . '" >' . $row['location'] . '</option>';
}
有什麼想法? 謝謝 Jim
我從第一個選擇完美的結果,但我需要使用查詢的結果填充第二個下拉框。 – Jim