also found this.  http://www.thickbook.com/extra/tb_loopoption.pdf




|--------+------------------------>
|        |          [EMAIL PROTECTED] |
|        |                        |
|        |          03/15/02 02:39|
|        |          PM            |
|        |                        |
|--------+------------------------>
  
>---------------------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                                                         |
  |      To:     Jeff Dale <[EMAIL PROTECTED]>                                      
                                                         |
  |      cc:     [EMAIL PROTECTED]                                             
                                                         |
  |      Subject:     Re: [PHP] Populating Dropdown with MYSQL data                    
                                                         |
  
>---------------------------------------------------------------------------------------------------------------------------------------------|




On Fri, 15 Mar 2002, Jeff Dale wrote:
> I want to have a dropdown list populated with data from my MySql server.
>
> Any examples or websites that could help is appreciated.

function outputSingleSelect()
// $name = name to give the HTML form element.
// $query = MySQL query. Should return 2 columns. First column
//    is the key, second is the label.
// $default = key of item to be preselected, if any.
// $labelchoice = instructional item (like "- Select a city -") to
//    place at the top of the list
{
        global $DEBUG;
        list ($name, $query, $default, $labelchoice) = func_get_args();
        if (!$query) return;
        if ($DEBUG) print "<br>Calling outputSingleSelect with $query";
        $st = mysql_query($query);
           if (mysql_errno()) return;
        $select = "<select name=\"$name\">";
        if ($labelchoice)
        {
                $select .= '<option value="**"';
                if (!$default) { $select .= ' selected'; }
                $select .= ">$labelchoice";
        }
        while ($row = mysql_fetch_row($st))
        {
                $select .= '<option value="' . $row[0] . '"';
                if ($default == $row[0]) { $select .= ' selected'; }
                $select .= '>' . $row[1];
        }
        $select .= '</select>';
        return (mysql_num_rows($st)) ? $select : '';
}



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






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

Reply via email to