Re: Populating a <select> form element.

From: Date: Fri, 08 Dec 2000 13:21:17 +0000
Subject: Re: Populating a <select> form element.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-29340@lists.php.net to get a copy of this message
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 (#29340) next »