Re: Multiple multiple selects

From: Date: Mon, 17 Jul 2000 04:40:16 +0000
Subject: Re: Multiple multiple selects
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6870@lists.php.net to get a copy of this message
At 2:26 PM -0700 7/16/00, Steff Osborne wrote:
Hi all, I have a question about handling several multiple select boxes. As we all know, doing multiple text boxes with the same name is easy: <input type="text" name="foo[]"> Handling one multiple select box is also easy: <select name="foo[]" multiple> But what about doing several multiple select boxes? <select name="foo[][]" multiple> doesn't seem to work. Can anybody give me some ideas? What I need for this is a 3-D array of $foo["select box"]["selected item"], and I can't seem to get that.
This won't work in PHP3 - I haven't tried PHP4, but I believe something like this _will_ work there. In PHP3, arrays in form variable names are limited to 1 dimension. A workaround is to do something like <select name="foo_1[]" multiple> ... <select name="foo_2[]" multiple> ... and then in the form processing program, do $i = 1; $var_name = 'foo_1'; while (is_array($$var_name)) { # Process elements of foo_i array (in $$var_name) $i++; $var_name = "foo_$i"; } You could also pass a 'foo_count' as a HIDDEN form variable and do for ($i=1; $i <= $foo_count; $i++) { $your_array = ${foo_$i}; # not 100% sure of this syntax # Process $your_array } - steve +--- unix and cats: -----------------------------------------------------+
| Steve Edberg                           University of California, Davis |
| sbedberg@ucdavis.edu                               Computer Consultant |
| http://aesric.ucdavis.edu/                   http://pgfsun.ucdavis.edu |
+----------------------- hard to befriend, but then friends for life! ---+

« previous php.general (#6870) next »