Hi, I hope this is of some help. Programmatically, the idea is: (html) begin a select input type (php) connect_to_db ---> query ---> add options (one at a time, in a loop) (html) end the select input type
The follwing code works for a table named projects with a field named project. Apply it however you want. "Passing the query results" is accomplished using mysql_fetch_array() and a while() loop in combination with the echo command to convert the $result (from mysql_db_query) to HTML output. This message is somewhat redundant considering Richard Hillström's response below, but I cut & pasted my method for doing the exact same thing (in almost, gee, exactly the same way...) :-@ Defaults to "None" (and will give this option even if the query fails, or the table is empty): <select name="proj_id"> <option value="None" selected> None </option> <?php mysql_connect('foo','foouser','foopass'); $query = "SELECT project FROM projects"; $result = mysql_db_query("metadata", $query); if ($result) { while ($r = mysql_fetch_array($result)) { $project = $r["project"]; echo "<option value=$project> $project </option>"; } } ?> </select> Cheers, -db "Mark C. Farrington" wrote: > Thanks for the quick response, but I'm still having a bit of difficulty with > it. > > I'll go into a bit more detail: > > I have my database and what I need in the dropdown is the results of a query > on the field unit_tag in a table named unit_name. > I see how the code snippet creates the dropdown box but I'm still fuzzy on > how to pass the query results. > > ----- Original Message ----- > From: "Richard Hillström (GIS)" <[EMAIL PROTECTED]> > To: "'Mark C. Farrington'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > Sent: Thursday, November 29, 2001 9:31 AM > Subject: RE: [PHP-DB] Converting MySOL query results into form elements. > > > I solved it like this: > > > > echo "<SELECT NAME='databasename'>"; > > while($row = sybase_fetch_array($dbresult)) { > > $r0 = $row[0]; > > echo "<OPTION VALUE='$r0'>$r0</OPTION>"; > > } > > echo "</SELECT><BR>"; > > > > > > //Richard > > > > -----Original Message----- > > From: Mark C. Farrington [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, November 29, 2001 3:25 PM > > To: [EMAIL PROTECTED] > > Subject: [PHP-DB] Converting MySOL query results into form elements. > > > > > > What I need to do is query a MySQL db and turn the results into a dropdown > box on a form. > > > > I've been paging through my books and I've come accross the command > writeOptionList which seems to be what I'm looking for but I'm not sure how > to use it. > > > > Self taught programming is a joy eh? > > > > Mark C. Farrington > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- ---------- Dan Barton Terrestrial Program Biologist Asst. Data Manager Point Reyes Bird Observatory http://www.prbo.org [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]