在选择第一个下拉框后,我有以下代码用于填充第二个下拉框(实际上它们都已经制作好了,它只是根据您的第一个下拉列表显示正确的下拉框:
<tr><th>Customer</th><td>
<select name='customer_id' id='customer_id'>
<option value=''>-- Select Customer --</option>
<?php
$results = Misc::customerDropDown();
while ($row = mysql_fetch_array($results)) {
echo "<option value='" . $row['customer_id'] . "'>" . $row['customer_name'] . "</option>";
}
?>
</select><span class='error'> * <?php echo $errors['customer_id']; ?></span>
</td></tr>
<?php
$results = Misc::customerDropDown();
$num_customers = mysql_num_rows($results);
$n = 1;
while ($row = mysql_fetch_array($results)) {
?>
<tr class='locations' id='locations<?= $row['customer_id'] ?>'><th>Customer Location</th><td>
<select name='customer_location<?= $n ?>'>
<option value=''>-- Customer Locations --</option>
<?
$location_results = Misc::locationDropDown($row['customer_id']);
while ($option = mysql_fetch_array($location_results)) {
echo "<option value='" . $option['location_id'] . "'>" . $option['location_name'] . "</option>";
}
?>
</select><span class='error'> * <?php echo $errors['customer_location']; ?></span></td></tr>
<? $n++;
} ?>
我遇到的问题是,无论我尝试了什么,最后一个“customer_location”下拉列表总是会被使用,因为当它提交时(我相信)会覆盖另外两个。
我尝试将 customer_location 设为一个数组(customer_location[]),但这只是让它认为(例如)有 3 个数组,而不是一个包含 3 个元素的数组。我还尝试(如图所示)通过将 $n 附加到每个位置的末尾来命名该位置,但是当我去参考该帖子时,我不知道如何因为我无法参考$_POST['customer_location$n']
想法?