Hi,
I have looked all over but have not been able to figure out this problem. I have a form with a multiple select list box. I then want to pass the selected items to another form. My problem is that I am using variable variables because the user can create this list box many times. Here is what I know so far:
This works but does not use the variable variables (no $i which is the loop variable)
echo '<div class="entry">
<p class="label"> Ethnicity</p>
<div class="field">
<select name="pEthnicity0[]" id="pEthnicity$i" size="10" multiple>';
//<option value="select" selected>Select Multiple</option>
echo '<option value="other">Other Ethnicity (enter below)</option>';
$array = explode(",", $prow['ethnic']);
$query = "select * from TEthnicity ORDER BY ethnicity";
$result = mysql_query($query) or die ("Couldn't execute query.");
while( $row = mysql_fetch_array($result, MYSQL_NUM) ) {
$selected = in_array($row[0], $array) ? 'selected=\"true\"' : '';
echo '<option value="', $row[0], '"', $selected, '>', stripslashes($row[1]), '</option>';
}
echo '</select>
</div>
</div>';
This does not work - php does not recognize it as an array and no data is being passed
echo "<div class='entry'>
<p class='label'> Neighborhood</p>
<div class='field'>";
echo "<select name='{pNeighborhood.$i}[]' id='pNeighborhood$i' size='10' multiple>";
//<option value="select" selected>Select Multiple</option>
echo '<option value="other">Other Neighborhood (enter below)</option>';
$array = explode(",", $prow['neighbor']);
$query = "select * from TNeighbor ORDER BY location";
$result = mysql_query($query) or die ("Couldn't execute query.");
while( $row = mysql_fetch_array($result, MYSQL_NUM) ) {
$selected = in_array($row[0], $array) ? 'selected=\"true\"' : '';
echo '<option value="', $row[0], '"', $selected, '>', stripslashes($row[1]), '</option>';
}
echo "</select>
</div>
</div>";
In case it has something to do with the single quotes versus the double quotes, I also know that the input text below works using variable variables:
echo "<div class='entry'>
<p class='label'> Name</p>
<div class='field'>
<input type='text' name='pname$i' value='$prow[2]' id='pname$i' size='32'>
</div>
</div>";
Any help would be greatly appreciated. I have searched many hours on the web without any success.
Thanks
kap