Jump to content

Archived

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

newman

php and select element

Recommended Posts

hi . i have an array of multiple select elements :

<select multiple name="addr[]">

<option value=1>first choice
<option value=2>second choice
<option value=3>third choice

</select>

<select multiple name="addr[]">

<option value=1>first choice
<option value=2>second choice
<option value=3>third choice

</select>
i want these two to be in 2 different indexes :

\[0\]=1
\[0\]=2
\[0\]=3

[1]=1
[1]=2
[1]=3


but it creates an array like this :

[0]=1
[1]=2
[2]=3
[3]=1
[4]=2
[5]=3

what's the solution to have an array like the one above ?
thanks in advance .

Share this post


Link to post
Share on other sites
you are using the same array name in your select tags? are you wanting to have 2 seperate arrays like this:

array1[0]
array1[1]
array1[2]

array2[0]
array2[1]
array2[2]

or are you wanting a 2d array that looks like this:

array[0][0]
array[0][1]
array[0][2]
array[1][0]
array[1][1]
array[1][2]

Share this post


Link to post
Share on other sites
if you want the latter, you'll have to specify the key in the select names:

[code]<select multiple name="addr[0]">[/code]

and so on.

Share this post


Link to post
Share on other sites
thanks for the replies . i tested what akitchin said :

<select name="addr[0]">
<option value="1">
<option value="2">
<option value="3">
</select>

<select name="addr[1]">
<option value="4">
<option value="5">
<option value="6">
</select>

but i get an array like this . the last option of each select element:

Array ( [0] => 3 [1] => 6 )

Share this post


Link to post
Share on other sites
[code]
<select name="addr[one][1]">
<option value="1">
<option value="2">
<option value="3">
</select>

<select name="addr[two][1]">
<option value="4">
<option value="5">
<option value="6">
</select>
[/code]

Share this post


Link to post
Share on other sites
redarrow's extra [1] is totally unnecessary, but perhaps changing the index you give in the input name to a string rather than a number will help.

Share this post


Link to post
Share on other sites

×

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.