Re: Populating a <select> form element.

From: Date: Fri, 08 Dec 2000 22:41:27 +0000
Subject: Re: Populating a <select> form element.
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-29353@lists.php.net to get a copy of this message
TVM! I'll digest thisover wkend! malc0 ----- Original Message ----- From: "Miles Thompson" <milesthompson@sprint.ca> To: "Malcolm Clark" <mal@sawds.com> Cc: <php-general@lists.php.net> Sent: Friday, December 08, 2000 5:21 AM Subject: Re: [PHP] Populating a <select> form element. > Here's some stuff, hope it helps. I'd probably use and inline if now instead of > creating the is_selected() function. > > // > // is_selected > // used to build an option list for a select list. > // returns "selected" if the option_expression is true > // CQA Consulting - 2000 > // > function is_selected( $option_expression ) > { > if ($option_expression) > { > $retval = "selected"; > } > else > { > $retval = ""; > } > return $retval; > } // end of function is_selected > > And the following to populate the select list. The "classes" are really product > descriptions like giftware, lingerie, housewares, etc. > > // > // build the select list for classes > // > // For the first element in the list it is important that the value be "" > // so that logic for the creation of the WHERE statement works correctly. > // > // The display also relies on array of classes, indexed by nClassKey, > // to display the item's class. We build it here. > // > $arClass = array(); > $option_class = "<option value = \"\" selected > All > </option>"; > $sql = "select * from class"; > $result = mysql_query( $sql ); > while( $row = mysql_fetch_array( $result ) ) > { > $nClassKey = $row["nClassKey"]; > $cClass = $row["cClass"]; > $selectval = is_selected( $ClassChoice == $nClassKey ); > $option_class .= "<option value = \"$nClassKey\" $selectval > >$cClass</option>"; > // add same data to arClass > $arClass[$row[nClassKey]] = $row[cClass]; > > } // end while $row = mysql_fetch... > > Hope this helps - Miles Thompson > > > > Malcolm Clark wrote: > > > I need to populate a single-choice <select> form element using data from > > MySQL. > > I then need to UPDATE the db using the user selection. > > > > Anybody got any code for this? I've gone bozeyed searching the various php > > sites. :| > > > > Shane McBride, I think you're saying you have code for a nav bar type drop > > down menu > > right? If, however, you've got code for my <select> tag problem, then please > > mail it and TIA! > > > > malco > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > >

« previous php.general (#29353) next »