Jump to content


Photo

php and select element


  • Please log in to reply
5 replies to this topic

#1 newman

newman
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 05 October 2006 - 05:34 PM

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 .



#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 October 2006 - 05:41 PM

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]

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 05 October 2006 - 06:02 PM

if you want the latter, you'll have to specify the key in the select names:

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

and so on.

#4 newman

newman
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 07 October 2006 - 11:03 AM

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 )

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 07 October 2006 - 01:38 PM

<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>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 07 October 2006 - 11:32 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users