Re: Populating a Dropdown Menu From a Query

From: Date: Fri, 16 Jul 2004 19:30:56 +0000
Subject: Re: Populating a Dropdown Menu From a Query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-190743@lists.php.net to get a copy of this message
> I have a form where one option is a dropdown menu. I'd like that menu to > only have items in it that are actually available. Selecting the items with > a query is easy enough but I wondered if anyone could tell me where to start > wit the code. I dont know what kind of db so I will just use mysql, this comes almost straight from the manual http://us3.php.net/mysql: $query = "SELECT * FROM my_table WHERE available"; $result = mysql_query($query) or die("Query failed : " . mysql_error()); /* Printing results in HTML */ echo "<select name=\"yourDropdownName\">\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value=\"$line[itemnum]\">$line[itemname]</option>\n"; } echo "</select>\n";

« previous php.general (#190743) next »