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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to