RE: Multiple multiple selects

From: Date: Sun, 16 Jul 2000 22:22:01 +0000
Subject: RE: Multiple multiple selects
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-6852@lists.php.net to get a copy of this message
Do you mean that you've got multiple boxes and you need to know which one has been checked? If so then you can set up the boxes on your form within a loop like:- <?php $loop = 0; while ($myrow = mysql_fetch_array($property_result)) { $loop++; $ref = $myrow["reference"]; $location = $myrow["location"]; $contact_email_name = $myrow["contact_email_name"]; ?> <input type="hidden" name="ref<?php echo $loop ?>" value="<?php echo $ref ?>"> <tr> <td width="100"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> <input type="checkbox" name="checkbox<?php echo $loop ?>" value="checked"><?php echo $ref ?></font></td> <td width="350"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?php echo $location ?></font></td> <td width="150"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><?php echo $contact_email_name ?></font></td> </tr> <?php } So you end up with fields called checkbox1, checkbox2, etc. In the script that reads the form you can find which boxes have been checked:- $loop = 0; // just a note about the $$ usage - with $$ PHP uses the contents of the variable as the actual // variable name while ($loop < $max_count) { $loop++; $boxname = "checkbox" . $loop; if ($$boxname == "checked") { $selected_count++; if ($selected_count == 1) { $refname = "ref" . $loop; $firstref = $$refname; $firstbox = $boxname; } } } So you find out which box has been checked and what the reference for the box is. Hope this helps. -----Original Message----- From: Steff Osborne [mailto:sosborne@xuma.com] Sent: Monday, July 17, 2000 9:27 AM To: php-general@lists.php.net Subject: Multiple multiple selects 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. Thanks!

« previous php.general (#6852) next »