apologies for answering such an already-over-answered question, but i feel
that no-one has given a particularly *good* answer, so i'll add mine to the
list. I use this function (as well as a couple others which do similar
things for all form elements;

// Creates an HTML select box of values.
// $options can be one or two dimensional, if one then indexes 0+ are used
as values
// $misc contains any key/value pairs you want added to the tag as
attributes, such
// as class, style or "multiple" attributes.
function display_select($name, $options, $value = 0, $misc = "unset") {
        $select = "<select";
        if (strlen($name))
                $select .= " name=\"" . $name . "\"";
        if (is_array($misc))
                while (list($id, $val) = each($misc))
                        $select .= " " . $id . "=\"" . $val . "\"";
        $select .= ">";
        if (is_array($options)) {
                while (list($id, $val) = each($options)) {
                        $select .= "\n<option";
                        $select .= " value=\"" . $id . "\"";
                        if (strcmp($id, $value))
                                $select .= ">";
                        else
                                $select .= " selected>";
                        $select .= htmlspecialchars($val) . "</option>";
                }
        }
        $select .= "\n</select>";
        return $select;
}




// -----Original Message-----
// From: B.J.Rumsey [mailto:[EMAIL PROTECTED]]
// Sent: Wednesday, 30 January 2002 2:30 PM
// To: php-db
// Subject: [PHP-DB] drop down list
// 
// 
// I have two fields artist_id, artist.  How do I put the 
// contents of "artist" into a dropdown list.
// 
// 
// -- 
// PHP Database Mailing List (http://www.php.net/)
// To unsubscribe, e-mail: [EMAIL PROTECTED]
// For additional commands, e-mail: [EMAIL PROTECTED]
// To contact the list administrators, e-mail: 
// [EMAIL PROTECTED]
// 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to