RE: [PHP] Help with multiple select

From: Date: Thu, 08 Aug 2002 22:51:46 +0000
Subject: RE: [PHP] Help with multiple select
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-111746@lists.php.net to get a copy of this message
Try: $mins = "2,3,5,6,7"; $ret = array_reverse(explode(',', $mins)); // now you have something like: // $ret[2] = 0; // $ret[3] = 1; // // etc, basically string became and array in reversed way... then in script... if(isset($mins[2])) ... if(isset($mins[3])) and so on ..... but, I would really recommend you to experiment some alternative ways with use of a loop. That would be way cleaner. Sincerely, Maxim Maletsky maxim@php.net PHP Beginner www.phpbeginner.com > -----Original Message----- > From: rdkurth@starband.net [mailto:rdkurth@starband.net] > Sent: Friday, August 09, 2002 12:38 AM > To: php-general > Subject: [PHP] Help with multiple select > > I need to get the data from the table and add it to the multiple > select statement below. What I am trying to do is give the user a form > to change his pervious selections. Now doing this if there is only one > thing > selected is easy. but I need a way to select multiple fields. The data > in $mins would look like this 8,13,15,20. I tried this little script > below but it does not work because of the , and I would also have to do > it for ever option value. There must be a shorter way of doing this. > > > $mins="2,3,5,6,7"; > > <TABLE><tr> > <td valign=top><select name="mins[]" size="12" multiple> > <option value="0">0 > <? if ($mins=="1"){?> > <option value="1" selected>1 > <?}else{?> > <option value="1">1 > <?}?> > <? if ($mins=="2"){?> > <option value="2" selected>2 > <?}else{?> > <option value="2">2 > <?}?> > <? if ($mins=="3"){?> > <option value="3" selected>3 > <?}else{?> > <option value="3">3 > <?}?> > <option value="4">4 > <option value="5">5 > <option value="6">6 > <option value="7">7 > <option value="8">8 > <option value="9">9 > <option value="10">10 > <option value="11">11 > <td valign=top><select name="mins[]" size="12" multiple> > <option value="12">12 > <option value="13">13 > <option value="14">14 > <option value="15">15 > <option value="16">16 > <option value="17">17 > <option value="18">18 > <option value="19">19 > <option value="20">20 > <option value="21">21 > <option value="22">22 > <option value="23">23 > </tr></table> > > -- > Best regards, > Richard Kurth > mailto:rdkurth@starband.net > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#111746) next »