RE: [PHP] 'Code Snippets' you couldn't live without

From: Date: Thu, 04 Nov 2004 07:58:48 +0000
Subject: RE: [PHP] 'Code Snippets' you couldn't live without
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-201133@lists.php.net to get a copy of this message
Another code snippet I use quite regularly builds a form select list from a delimited string. function displayFormSelect($selvals, $selname, $val=''){ $optval = explode(",", $selvals); $retval = "<select name='$selname'>"; foreach ($optval as $key => $value){ $retval .= "<option value='".$value."'"; if ($value == $val) $retval .= " selected"; $retval .= ">".$value."</option>"; } $retval .= "</select>"; return $retval; } Basically, I use it like so: $optstring = 'Option 1,Option 2,Option 3'; $optname = 'frmoptions'; $optsel = 'Option 3'; $formsel = displayFormSelect($optstring, $optname, $optse); echo $formsel; The optional third value defines the option that appears 'selected' if provided. Looking at it, it would be pretty easy to change this to pass a recordset array to it etc. Much warmth, Murray http://www.planetthoughtful.org Building a thoughtful planet, One quirky comment at a time.

« previous php.general (#201133) next »