Re: retrieving multi-select form values
| From: | Kevin Stone | Date: | Wed, 30 Jul 2003 22:03:00 +0000 |
| Subject: | Re: retrieving multi-select form values | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-157608@lists.php.net to get a copy of this message | ||
"Hank Tt" <no_spam@lomaji.com> wrote in message
news:004e01c356e4$8aea77e0$2e024482@hank...
> Given the following querystring generated by, for example, a multi-select
> form list (menu), the contents of $_GET['list'] is expected to be an array
> holding 3 elements:
>
> http://awebsite.net/formlist.php?list=2&list=3&list=99
>
> Yet I only see the last value returned as a lone string. Is this
expected?
>
> Thanks.
Yup it's working perfectly. $_GET['list'] overwrites $_GET['list']
overwrites $_GET['list']. You will only ever see the last one. Instead add
square brackets to each variable name..
http://awebsite.net/formlist.php?list[]=2&list[]=3&list[]=99
Now $_GET['list'] is an array wth three elements.
echo $_GET['list'][0]; // prints 2
echo $_GET['list'][1]; // prints 3
echo $_GET['list'][2]; // prints 99
To do this within your multi-select form field add the square brackets to
the field name...
<select name="list[]" select-multi>
<option></option>
<option></option>
<option></option>
</select>
In the future you might consider performing a search on Google Groups prior
to posting on the list. 9 out of 10 times you'll find the answer you're
looking for. This topic is particularly common.
-Kevin