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

Recommended Answers

All 5 Replies

Member Avatar for Rhyan

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

Such an action is created easier with Javascript. Still you can do it with php, but after clicking on the drop-down menu, the form will be submited and code revalidated in order to show the value you expect.

If you want to know how to create the drop down menu using php - go through the threads from last week - I think there is at least 2 posts with the same problem. For the JS script - it is a completely different story.

Good luck.

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:

$sql = "select username, email from Users LIMIT 10";

The Structure of the HTML <select> is:

<select name="box_name" id="box_id">

<option value="value1">Label 1</option>
<option value="value2">Label 2</option>

</select>

You'll probably want to generate something like:

<select name="user_email" id="user_email">

<option value="email1">User Name 1</option>
<option value="email2">User Name 2</option>

</select>

Thanks for the help digital-ether, got it working.

You're welcome. :)

can u explain me what exactly does d keywords like box_name , value1 n all mean"? m a fresher . n m not able to understand

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.