RE: Code for drop down lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If the list is something that may change more than just coccasionally, then
use the database field value. If its going to be really static, then hard
code it into the web form.

Now the code:

<?php
$drop_down_list = "<select name=HEI_ID>";
$link = mysql_connect ('localhost', 'user', 'password') // Connects to
database server
or die ("Could not select db");
mysql_select_db ('Heronsql') // opens database
or die ("Could not connect");
$query="select distinct Nickname, HEI_ID from Customers where (Nickname <>
'') order by Nickname"; // sets up the find
$result = mysql_query ($query); // runs the find
$num = mysql_num_rows($result); //goes thru each row building the display
        for ($i = 0; $i < $num; $i++) {
            $HEI = mysql_result($result, $i, "Nickname");
            $HEI_ID = mysql_result($result, $i, "HEI_ID");
            $drop_down_list .= "<option value=$HEI_ID>$HEI</option>";
        }
mysql_close($link);

$drop_down_list .= "</select>";

echo "$drop_down_list"; // prints the display

?>

This works for me on both Linux and Win servers.

Cheers

George

> -----Original Message-----
> From: Roland Perez [mailto:Roland.Perez@usdoj.gov]
> Sent: 11 February 2003 5:03 pm
> To: Receipt Notification Requested
> Subject:  Code for drop down lists
>
>
> I am a novice to PHP and am trying toget a survey with drop down lists.
> I am stuck as to if I should connect to the DB (MySQL DB) to get the
> values from a table or do I imbed them in the php file?
>
> Thanks for any help in advance.
> Roland Perez
> roland.perez@usdoj.gov
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux