homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Pulling info from MySQL
Placing in a dropdown box - Any Help?

 11:51 am on Dec 10, 2004 (gmt 0)

I need to add a drop down box to a HTML form but, I need the choices in the box to be pulled directly from a field in MySQL. Any ideas on how to do this?


Paul in South Africa

 12:07 pm on Dec 10, 2004 (gmt 0)

This should point you in the right direction

$result = mysql_query("SELECT * FROM $table");
while ($a_row = mysql_fetch_row($result))
print "<option value=\"$a_row[0]\"";
if ($id == $a_row[0])
print "selected";
print ">$a_row[1]</option>\n";


 12:41 pm on Dec 10, 2004 (gmt 0)

Thanks Paul! Will this work to pull all of the customers in the customer field?

Paul in South Africa

 1:01 pm on Dec 10, 2004 (gmt 0)

You will have to adjust the query to get the information you require out of the database table.

$result = mysql_query("SELECT * FROM $table"); will select all records from a table. To help you in your specific situation we need to know what fields your table has and what information you need to extract.


 2:05 pm on Dec 10, 2004 (gmt 0)

The table is "customers" the fields are as follows. 'client name', 'bill to address', 'shipping address', 'phone', 'contact name'.

I want the 'client name' choices to display in the drop down box and once the client name is selected all of their information will be pulled from the table. I guess my problem is getting all of the client names in the database to display in the dropdown box as an option to select.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved