Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Posts
    388
    Thanks
    0
    Thanked 0 Times in 0 Posts

    multiple selections in a form

    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?

    Code:
    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

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Your problem is here:
    Code:
    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.
    Code:
    $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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •