RE: [PHP-WIN] newbie question on <select> and php.

From: Date: Fri, 22 Dec 2000 01:31:28 +0000
Subject: RE: [PHP-WIN] newbie question on <select> and php.
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-4590@lists.php.net to get a copy of this message
Hi Larry, Try this: function doDropList($options,$selected) { $i = 0; while (list($key,$value)=each($options)) { $html .= "<OPTION VALUE=\"$value\""; if (empty($selected) && $i==0) { // select the first item if nothing selected $html .= " SELECTED"; } else { if(!empty($selected)) { if (is_array($selected)) { if (in_array($value,$selected)) { $html .= " SELECTED"; } } else { if ($selected==$value) { $html .= " SELECTED"; } } } } $html .= ">$key</OPTION>\n"; $i++; } return $html; } Ignatius > -----Original Message----- > From: Larry Hotchkiss [mailto:lhotch@unicap.com] > Sent: Friday, 22 December 2000 04:02 > To: 'PHP windows list' > Subject: [PHP-WIN] newbie question on <select> and php. > > > Ok I will try to be brief and complete. I am enforcing some > RI in my > tables by loading drop down boxes (ie. select) in forms on my a couple > pages where records are added. I also have a few forms that get > prepopulated from a table for editing/modifying records. > > Now, in the above forms for modifying, all fields are > populated with > current record data except one which just displays the records value as > text and below it gives a dropdown (select) in order to change that field > and still maintain RI. The problem I am having is that the dropdown > defaults to the first retreived item, which of course does not > always match > the records current value. This forces the person who is modifying the > record to make sure that they change the dropdown to equal the current > value if that is something they dont want changed since my submit > 'updates' > all the fields. > > I am thinking of two options here. One, I can just not > allow the field in > question to be changed and instead force the record to be deleted and > readded which inforces RI. OR, I would like to be able to have the drop > down (select) default to the current field value.....did all this make > sense? > > Thanks for any input. > > --------------------------------- > Larry Hotchkiss > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.windows (#4590) next »