Jump to content


Photo

multiple select reading


  • Please log in to reply
4 replies to this topic

#1 mojito

mojito
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 17 May 2006 - 04:15 PM

Hi freaks

Im comming back into some form problems, i thought a multiple select form sent a comma separated values but when using and selecting multiple options the query string is like

select=me&select=too&Submit=Submit

do i have to iterate through each select and make an array myself?

thanks

mojito



#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 17 May 2006 - 04:30 PM

Try HTML: <select multiple name="myselectbox[]"> ... </select>

XHTML: <select multiple="multiple" name="myselectbox[]"> ... </select>


PHP:

$selections = $_GET['myselectbox']; // or $_POST

for ($i = 0, $cnt = count($selections); $i < $cnt; $i++) {

echo 'You selected: ', $selections[$i], '<br/>';

}

or:

$selections = $_GET['myselectbox']; // or $_POST

foreach ($selections as $choice) {

echo 'You selected: ', $choice, '<br/>';

}


Edit: Forgot "multiple" so I added it - thx kenrbnsn. I'm sure mojito has mutiple already specified since his post shows he's getting: select=me&select=too

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 May 2006 - 04:31 PM

Please post the souce for your form.

You need to make the name of the select list an array.
<select name="select[]" multiple>

Ken

#4 mojito

mojito
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 17 May 2006 - 09:24 PM

[!--quoteo(post=374714:date=May 17 2006, 04:31 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 17 2006, 04:31 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Please post the souce for your form.

You need to make the name of the select list an array.
<select name="select[]" multiple>

Ken
[/quote]

yer i tried that and the result is

select%5B%5D=me&select%5B%5D=too&Submit=Submit

so its just encoding the brackets, and not making an array.
here is my source
<select name="select[]" size="2" multiple="multiple">
    <option value="me">1</option>
    <option value="too">2</option>
  </select>

m

#5 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 17 May 2006 - 09:31 PM

[!--quoteo(post=374788:date=May 17 2006, 02:24 PM:name=mojito)--][div class=\'quotetop\']QUOTE(mojito @ May 17 2006, 02:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
yer i tried that and the result is

select%5B%5D=me&select%5B%5D=too&Submit=Submit

so its just encoding the brackets, and not making an array.

m
[/quote]
it will be an array if you try
print_r($_GET['select']);

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users