Re: Populate Popup Menu from Database
| From: | Mike Tuller | Date: | Mon, 01 Jul 2002 20:22:21 +0000 |
| Subject: | Re: Populate Popup Menu from Database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-104774@lists.php.net to get a copy of this message | ||
Thanks. Here is what I did for future reference.
<select name = "departments">
<option value = ''> -- Select a Department -- </option>
<?
$connection = mysql_connect( "127.0.0.1", "username", "password")
or die
("Could not connect");
$db = mysql_select_db ("asset") or die ("Could not connect");
$sql = "select department_name from Departments";
$sql_result = mysql_query($sql,$connection) or die ("Could not
connect");
while($row = mysql_fetch_array($sql_result))
{
$department = $row["department_name"];
echo "<option value = '$department'>$department</option>";
}
?>
</select>
> From: Erik Price <pricee@hhbrown.com>
> Date: Mon, 1 Jul 2002 09:18:12 -0400
> To: Mike Tuller <php@ce.anoka.k12.mn.us>
> Cc: php mailing list <php-general@lists.php.net>
> Subject: Re: [PHP] Populate Popup Menu from Database
>
>
> On Saturday, June 29, 2002, at 11:41 AM, Mike Tuller wrote:
>
>> What is here is beyond my understanding, and seems like it is a little
>> much
>> for what I need.
>>
>> Here is what my database table looks like:
>>
>> Departments
>> department_id
>> department_name
>>
>> I just want to list the department name in the popup.
>
> although I wrote this instruction in response to a question about
> integrating the listbox with javaScript, ignore the JS stuff, and you
> will see how to dynamically populate a listbox with database data:
>
>
> http://marc.theaimsgroup.com/?l=php-general&m=102503848224300&w=2
>
>
>
> ----
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> pricee@hhbrown.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>