Jason Stechschulte 21 July 2002 19:18:34 [ permanent link ]
On Sun, Jul 21, 2002 at 11:43:25AM -0400, WANDA HANSEN wrote:> Is there a way to handle data gathered from a drop down menu that> allows multiple selections using PHP?
Yes. The way I normally do this is to use HTML that looks something like:
Hello,>> Is there a way to handle data gathered from a drop down menu that>allows>> multiple selections using PHP?>
Of course. Name your select box as an array, and include the 'multiple'>keyword.>
<select name='something[]' multiple>>
Then you'll have an array on your processing page that holds all of the>values that were selected. $_POST['something'][]. Note that it starts at>zero. >
You can use count($_POST['something']) to see how many were selected,>etc...
If you need specific IDs or something from the OPTIONs presented, other than the text between the tags, you can even use the VALUE= attribute to pass around data so that $_POST['something'] doesn't just start at 0 and count up:
Hello,>> Is there a way to handle data gathered from a drop down menu that>allows>> multiple selections using PHP?>
Of course. Name your select box as an array, and include the 'multiple'>keyword.>
<select name='something[]' multiple>>
Then you'll have an array on your processing page that holds all of the>values that were selected. $_POST['something'][]. Note that it starts at>zero. >
You can use count($_POST['something']) to see how many were selected,>etc...
If you need specific IDs or something from the OPTIONs presented, other than the text between the tags, you can even use the VALUE= attribute to pass around data so that $_POST['something'] doesn't just start at 0 and count up:
-----Original Message-----> From: Richard Lynch [mailto:rich@phpbootcamp.com]> Sent: Sunday, July 21, 2002 5:06 PM> To: php-general@lists.php.net> Subject: Re: [PHP] Drop Down Box Question>
Hello,> >> Is there a way to handle data gathered from a drop down menu that> >allows> >> multiple selections using PHP?> >
Of course. Name your select box as an array, and include the
'multiple'> >keyword.> >
<select name='something[]' multiple>> >
Then you'll have an array on your processing page that holds all of
values that were selected. $_POST['something'][]. Note that it starts
zero.> >
You can use count($_POST['something']) to see how many were selected,> >etc...>
If you need specific IDs or something from the OPTIONs presented,
other> than> the text between the tags, you can even use the VALUE= attribute to pass> around data so that $_POST['something'] doesn't just start at 0 and count> up:>
If you click on Spock, instead of just 0, Spock, you'll get 2, Spock
--> You> get his ID number as well as his name.
That's confusing. There's no way to get "Spock" from the code. You only get the number in the value attribute. If the user were to choose Spock and McCoy, then you'd have:
If you would like to report an abuse of our service, such as a spam message, please . Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .