Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP Question

PHP Question
Thread Tools
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jun 9, 2004, 01:45 PM
 
Hi,

I have a form with those listboxes, where you can select multiple names.

How do I send that to PHP as an array? Checkboxes work if I name them all "name[]" in the HTML, but when I try that with this multiple selection boxes, the numbers just get appended to each other, and it's not an array. It's a string.

Thanks!
     
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status: Offline
Reply With Quote
Jun 9, 2004, 02:02 PM
 
I'm unable to test this currently, but couldn't you do something along these lines:

[php]
<select name='items[]' multiple>
<option value='1'>Apples</option>
<option value='2'>Oranges</option>
</select>
[/php]

Then, depending on how your instance of PHP is configured, you would just access the form values in a standard way ($_POST['items'] or $items if you have PHP configured to automatically store the form values in respective variable names):

[php]
// iterate over all values in items[] array
for ($i = 0; $i < count ($items); $i++) {
print "Value $i is $items[$i]\n";
}

// or do whatever you want with the values in the array
[/php]

Hope this helps.
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
     
Mac Enthusiast
Join Date: Jan 1999
Location: Marietta, GA, USA
Status: Offline
Reply With Quote
Jun 11, 2004, 02:46 PM
 
Hehe, I tried to respond to this, but must have clicked the Add Topic button. Anyway, try this:

http://us3.php.net/variables.external
Scott Genevish
scott AT genevish DOT org
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:35 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2