...

View Full Version : multiple selections in a form



davehaz
06-18-2006, 04:09 AM
howdy,
I have written a script using php that pulls a column from a mysql db, I am making a dropdown menu where hopefully the user can make multiple selections out of it, the problem is that when i echo the post variables only the last selection is shown, below is the code I am using, how do I get all the selections made into my post variable?



echo "<form name='menu' action='{$_SERVER['PHP_SELF']}' method='post'>";
echo "<table><tr><td colspan='2'>Choose the merchants not to include in the PPC List.<br />Mulitiple selections available by holding the CTL key down</td></tr><tr>";
echo "<td><select name='items' multiple size='20'>";
$menu_select = "SELECT DISTINCT merchant FROM table ORDER BY merchant ASC";
$menu_result=mysql_query($menu_select);
while($menu=mysql_fetch_array($menu_result)){
$menu_data=$menu['0'];
echo "<option value='$menu_data' name='$menu_data'>".$menu_data."</option>";
}
echo "</select></td><td align='left'><input type='submit' name='submit' value='submit'>";
echo "</td></tr>";
echo "</table></form>";
if(isset($submit)){
foreach($_POST as $value){
echo $value."<br />";
}
}

tia

guelphdad
06-18-2006, 04:04 PM
Your problem is here:


while($menu=mysql_fetch_array($menu_result)){
$menu_data=$menu['0'];

you are assigning the same value each time.

instead of a while loop do this.


$count = mysql_num_rows($menu_result);
for ($loop = 0; $loop <$count; $loop++) {
$menu_date=$menu_result[$loop]
}


Oh, one last point, don't use '0' when you mean zero. Don't include quotes around numeric data.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum