By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,745 Members | 1,867 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,745 IT Pros & Developers. It's quick & easy.

getting multiple data from <select>

P: n/a
Can anyone give me a quick hint for this?

Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>

Then I'd like to list the items selected...
echo $_POST["opt3"];
but this gives only the first one

how do I get the rest?

Feb 6 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Sonnich" <so************@elektrobit.comkirjoitti
viestissä:11*********************@s48g2000cws.goog legroups.com...
Can anyone give me a quick hint for this?
Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>
Then I'd like to list the items selected...
echo $_POST["opt3"];
but this gives only the first one
how do I get the rest?

<SELECT NAME="opt3()" SIZE="15" multiple>

Parenthesis is the point: NAME="opt3()"

Then php knows than an array is coming. This is not because html would
require that, but because php does. This applies not only to select
elements, but checkboxes as well for example. Or sometimes you may want to
send some array in hidden fields.

Feb 6 '07 #2

P: n/a
On Feb 6, 4:36 pm, "P Pulkkinen"
<perttu.POISTATAMA.pulkki...@POISTATAMA.elisanet.f iwrote:
"Sonnich" <sonnich.jen...@elektrobit.comkirjoitti
viestissä:1170772126.596200.67...@s48g2000cws.goog legroups.com...
Can anyone give me a quick hint for this?
Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>
Then I'd like to list the items selected...
echo $_POST["opt3"];
but this gives only the first one
how do I get the rest?

<SELECT NAME="opt3()" SIZE="15" multiple>

Parenthesis is the point: NAME="opt3()"

Then php knows than an array is coming. This is not because html would
require that, but because php does. This applies not only to select
elements, but checkboxes as well for example. Or sometimes you may want to
send some array in hidden fields.
eeehhh I tried to play a bit around with this, but do I also need a
trick to read it out?

BR
Sonnich

Feb 6 '07 #3

P: n/a

"Sonnich" <so************@elektrobit.comwrote

"eeehhh I tried to play a bit around with this, but do I also need a
trick to read it out?"

Well, you need to loop through the array:

foreach ($opt3 as $key =$val)
{
echo "<p>".htmlspecialchars($key)."=".htmlspecialchars( $val)."</p>n";
}

That's something for ONE-dimensional array, though. Remember, no parenthesis anymore.
Feb 6 '07 #4

P: n/a
Rik
Sonnich <so************@elektrobit.comwrote:
On Feb 6, 4:36 pm, "P Pulkkinen"
<perttu.POISTATAMA.pulkki...@POISTATAMA.elisanet.f iwrote:
>"Sonnich" <sonnich.jen...@elektrobit.comkirjoitti
viestissä:1170772126.596200.67...@s48g2000cws.goo glegroups.com...
Can anyone give me a quick hint for this?
Say, I have: <SELECT NAME="opt3" SIZE="15" multiple>
Then I'd like to list the items selected...
echo $_POST["opt3"];
but this gives only the first one
how do I get the rest?

<SELECT NAME="opt3()" SIZE="15" multiple>

Parenthesis is the point: NAME="opt3()"

Then php knows than an array is coming. This is not because html would
require that, but because php does. This applies not only to select
elements, but checkboxes as well for example. Or sometimes you may want
to
send some array in hidden fields.

eeehhh I tried to play a bit around with this, but do I also need a
trick to read it out?

Well, don't use () in the name, but []...

A little hint for debugging POSTs: echo file_get_contents('php://input')
will give you the raw input.

Example:
------------------
POST:
<?php
var_dump($_POST);
?>
INPUT:
<?php
echo file_get_contents('php://input');
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="check()" multiple>
<option>option 1</option>
<option>option 2</option>
<option>option 3</option>
<option>option 4</option>
<option>option 5</option>
<option>option 6</option>
</select>
<select name="check2[]" multiple>
<option>option q</option>
<option>option e</option>
<option>option r</option>
<option>option t</option>
<option>option y</option>
<option>option u</option>
</select>
<input type="submit">
</form>
------------------
--
Rik Wasmus
Feb 6 '07 #5

P: n/a

"Rik" <lu************@hotmail.comwrote
Well, don't use () in the name, but []...
Oops, thanks for correction.
Feb 6 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.