我正在尝试根据另一个下拉框中的选择填充一个下拉框。这是我的 php 代码:
<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>
当我运行查询时,一切都很好,但我需要获取此结果并使用它来填充另一个下拉框(<'value from previous drop down'>),它位于此处:
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>';
}
有什么想法吗?谢谢吉姆