Getting values From multiple Combo Box

Hi guys, I don’t know what is wrong with my code. I am creating multiple combo box based on the the resultset of my database. However, I don’t know how the the value being selected…I create the object as


for($x = 0; $x < $position['posindex']; $x++)
{
      echo "<select name='cboPosition'>";
      $query = "SELECT .........";
      $result = mysql_query($query);

      echo "<option value=''></option>";
      while($nominee = mysql_fetch_array($result))
      {
            echo "<option value='$nominee[id]'>
                                    $nominee[name]</option>";
      }

      echo "</select>";
}

And for me to get the value


    if($_POST['btnSubmit'])
    {
      
      foreach($_POST['cboPosition'] as $key)
        echo $key;
    }

Please help me, there no value being return when I click on the submit button.

Start with <select name=‘cboPosition’> and see if that does what you’re hoping for.

You’re missing quotes where you echo the <option>s but that would give a parse error so I’m assuming that’s not in the actual code.

I’m sorry, I have to write it as <select name=‘cboPosition’>…still it doesn’t work.

use after the select name as mentioned, and you’ll also need the multiple attribute.


<select name="cboPosition[]" multiple="multiple">
</select>

Try this…


for($x = 0; $x < $position['posindex']; $x++)
{
      echo '<select name="cboPosition[]">';
      $query = "SELECT .........";
      $result = mysql_query($query);

      echo "<option value=''></option>";
      while($nominee = mysql_fetch_array($result))
      {
            echo<option value='$nominee[id]'>
                                    $nominee[name]</option>";
      }

      echo "</select>";
}

And this


    if($_POST['btnSubmit'])
    {
     $cboPosition=$_POST['cboPosition'];
	if ($cboPosition){
	 foreach ($cboPosition as $value){
              echo 'You selected ',$value,'<br />';
        }
    }


Yes - you have to use arrays!

I did the same thing but it doesn’t works.

Thanks to all of you guys…now it works. I haven’t notice in my actual code that I overdo a statement.