Jump to content

multiple select reading


mojito

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/9865-multiple-select-reading/#findComment-36658
Share on other sites

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

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

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
[code]<select name="select[]" size="2" multiple="multiple">
    <option value="me">1</option>
    <option value="too">2</option>
  </select>[/code]

m
Link to comment
https://forums.phpfreaks.com/topic/9865-multiple-select-reading/#findComment-36732
Share on other sites

[!--quoteo(post=374788:date=May 17 2006, 02:24 PM:name=mojito)--][div class=\'quotetop\']QUOTE(mojito @ May 17 2006, 02:24 PM) [snapback]374788[/snapback][/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
[code]print_r($_GET['select']);[/code]
Link to comment
https://forums.phpfreaks.com/topic/9865-multiple-select-reading/#findComment-36735
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.