At 11:48 AM 12/18/2001 +0100, Martin.Andrew wrote:
>I want to use a combo box with multiple select enabled.
>Selecting one value works fine but when I select multiple values only the
>last value is saved in the DB.
>
>you must be able to use this function in PHP, right?

Name the select box as an array.  For example:
<select multiple name="colors[]" size="4">
   <option value="red">Red</option>
   <option value="blue">Red</option>
   <option value="green">Red</option>
   <option value="yellow">Red</option>
</select>

Then when you submit the form, you will have an array $colors.  Note that 
the array will not be of size four necessarily: it will be of the size of 
the number of options selected.  If they select none of the options then it 
will be of sizeof 0.  So you can check by looping through.  Each value of 
the array is the value of one of the options that was selected.

if (sizeof($colors) > 0) {
   for ($idx = 0; $idx < sizeof($colors); $idx++) {
     // do stuff with the values of $colors[$idx].
   }
}
else {
   // no options were selected.
}

-Mike



-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to