Re: Populating Dropdown with MYSQL data
| From: | Daniel Negron/KBE | Date: | Fri, 15 Mar 2002 22:44:36 +0000 |
| Subject: | Re: Populating Dropdown with MYSQL data | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-88712@lists.php.net to get a copy of this message | ||
also found this. http://www.thickbook.com/extra/tb_loopoption.pdf
|--------+------------------------>
| | mnc@stoic.net |
| | |
| | 03/15/02 02:39|
| | PM |
| | |
|--------+------------------------>
>>---------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| To: Jeff Dale <jeff.dale@compaq.com>
|
| cc: php-general@lists.php.net
|
| 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