View Full Version : multiple selections in a form

06-18-2006, 05:09 AM
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";
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>";
foreach($_POST as $value){
echo $value."<br />";


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


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++) {

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