943,192 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 27556
  • PHP RSS
Mar 8th, 2007
0

Convert database values into Dropdown List

Expand Post »
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
Similar Threads
JSR
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JSR is offline Offline
5 posts
since Mar 2007
Mar 8th, 2007
0

Re: Convert database values into Dropdown List

Click to Expand / Collapse  Quote originally posted by JSR ...
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.
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Mar 11th, 2007
0

Re: Convert database values into Dropdown List

Click to Expand / Collapse  Quote originally posted by JSR ...
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]
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Mar 13th, 2007
0

Re: Convert database values into Dropdown List

Thanks for the help digital-ether, got it working.
JSR
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JSR is offline Offline
5 posts
since Mar 2007
Mar 13th, 2007
0

Re: Convert database values into Dropdown List

You're welcome.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Nov 25th, 2011
0
Re: Convert database values into Dropdown List
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sush.princess is offline Offline
1 posts
since Nov 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help!!!
Next Thread in PHP Forum Timeline: sort all values to be equal based on average and print details





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC