Multiple Selections from List Box
| From: | Stuart Felenstein | Date: | Sun, 03 Oct 2004 14:35:09 +0000 |
| Subject: | Multiple Selections from List Box | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-36559@lists.php.net to get a copy of this message | ||
I'm creating some multiple selection list boxes.
I believe this would be close to the correct code to
pull the selections:
<select name="select" size="3" multiple="multiple">
<?php $arrayselect = explode(" ", "Please
Select"); ?>
<option value="NY" <?php for ($i=0;
$i<sizeof($arrayselect); $i++) {if ("NY" ==
$arrayselect[$i]) {echo "selected"; break;}}?>>New
York</option>
<option value="SF" <?php for ($i=0;
$i<sizeof($arrayselect); $i++) {if ("SF" ==
$arrayselect[$i]) {echo "selected"; break;}}?>>San
Francisco</option>
<option value="LA" <?php for ($i=0;
$i<sizeof($arrayselect); $i++) {if ("LA" ==
$arrayselect[$i]) {echo "selected"; break;}}?>>Los
Angeles</option>
<option value="DC" <?php for ($i=0;
$i<sizeof($arrayselect); $i++) {if ("DC" ==
$arrayselect[$i]) {echo "selected";
break;}}?>>Washington D.C.</option>
</select>
</form>
The values from the table are stores by valueID and
Label. Not sure if I need some kind of delimiter in
my code ?
Also, what is the most effective way to store the
selections in the database ? I'm assuming it would be
an "enum" column.
Stuart