get data from database and display it in a drop-downlist box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

get data from database and display it in a drop-downlist box

Post by zplits »

Hello there everyone. Good day. Does anyone here know how to get data from the database and display it in the drop-down list box? What will be the code?

Here is my database info:
table name : supplies
fields:
supplies_PK
code
name
price

here is the code for html drop-down list

Code: Select all

<select name="[b][color=#BF0000]code[/color][/b]" size="1" class="formFieldsDropDownCode" id="code" tabindex="4">
and here is the screenshot:
Image

Please help me. Thank you very much.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: get data from database and display it in a drop-downlist box

Post by jaoudestudios »

Just do a query and put a while loop around the html code for the select options.
User avatar
zplits
Forum Contributor
Posts: 158
Joined: Sun Aug 03, 2008 8:59 pm

Re: get data from database and display it in a drop-downlist box

Post by zplits »

Thanks for the response. Can you please provide the code? I'm sorry. I'm new in php. I hope you understand. Thanks a lot.
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: get data from database and display it in a drop-downlist box

Post by Stryks »

First, come up with a query to pull all the values you want to list from the database.

Then look at the HTML for a select and take note of the tags that would need to be added to insert an option to the list.

Then, loop through the options returned by your query, just like you did for displaying rows of data elsewhere, and on each loop, echo the HTML and values that will add the options needed to the final markup.

Give it a shot, and if you have any trouble ... take a look at the HTML source you are producing. See if you can see what isn't showing up the way it should, and what you can do to make it behave.

Cheers
Post Reply