Hi Guys, new to this forum, kinda new to PHP in general haven't been using it long, mostly creating forms for database and custom CMS modules.
Anyway, i'm building a html email tool from the ground up and just need some help with one thing.
How do i convert values from a database field into a html form drop-down list?
I want to make a the list that display individual users and if you select a user, the value becomes that users email address
Theres two things you'll need to know.
1) How to Query the Database with PHP.
2) The structure of the HTML <select> field (drop-down list)
Assuming you're using MySQL database, look here for the functions:
http://php.net/mysql
Lets say you have a Table: Users with columns username, and email
The SQL to select usrs and email would be:
[PHP]$sql = "select username, email from Users LIMIT 10";[/PHP]
The Structure of the HTML <select> is:
[PHP]
<select name="box_name" id="box_id">
<option value="value1">Label 1</option>
<option value="value2">Label 2</option>
</select>[/PHP]
You'll probably want to generate something like:
[PHP]<select name="user_email" id="user_email">
<option value="email1">User Name 1</option>
<option value="email2">User Name 2</option>
</select>[/PHP]