I have the following code I am using to populate a second dropdown box after the first dropdown box is selected (actually they are all already made, it just reveals the correct one based on your first dropdown:
<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++;
} ?>
The problem that I'm having is that no matter what I've tried the last 'customer_location' dropdown is the one that always gets used because when it submits it's (I believe) overwriting the other two.
I tried making customer_location an array (customer_location[]) but that just makes it think there are (for example) 3 arrays instead of an array with 3 elements. I also tried (as shown) naming the location by tacking on a $n to the end of each one but then when I go to reference the post I don't know how as I can't reference $_POST['customer_location$n']
Ideas?