我有下面的代码,我选择第一个下拉框后填充第二个下拉框(实际上它们都已经制作完成,它只是显示了基于您的正确的一个第一个下拉:jQuery/PHP/MySQL提交隐藏的选择下拉列表
<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 []),但这只是让它觉得有(对于exa mple)3个数组,而不是3个元素的数组。我也尝试过(如图所示),通过在每个元素的末尾添加一个$ n来命名位置,但是当我去参考帖子时,我不知道如何,因为我不能参考$_POST['customer_location$n']
想法?
在客户端,它全部通过jQuery的onChange显示。我如何能够知道在服务器端的帖子中使用哪一个?欣赏错字帮助。我假设有一个for($ n = 1; $ n <= $ count; $ n ++),但我仍然不能在$ _POST ['customer_location']上附加$ n – 2012-08-12 03:55:36
我看到您的笔记,我可以参考$ _POST ['customer_location1'],但我永远不会知道我有多少customer_location条目。有些客户可能有1个,其他客户可能有30个。 – 2012-08-12 04:00:15
您可以找到所有customer_locationN参数,其循环方式如下:'foreach($ _POST as $ key => $ value)if(preg_match('/^customer_location /',$ key ))...' – Barmar 2012-08-12 04:07:53