Create a Drop Down List with PHP

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
mustafamisir
Forum Newbie
Posts: 23
Joined: Wed Jun 22, 2005 1:00 pm
Contact:

Create a Drop Down List with PHP

Post by mustafamisir »

Hi all,

Now, I have been creating a web site which is about cell phones, so I want to add some good properties to the site. I did some, but I could not create a drop down list whose each element comes from a database. When a person enter the site, he or she must see a drop down list and choose one choice, and then this choice must go to the database and check whether the choice is available in tha database. If it is available, the page must give a new page which includes the properties of the phone that takes all the information from the database.

I can use the database, but I could not write the code with PHP.

Thank you for now...
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

sure exactly what you mean I am not:

if create a dropdown list from database is all you need the followig you should try:

Code: Select all

$result = mysql_query("select id, phonename from phones")
  or die(mysql_error());
$stuff = "<select name=\"phone\">";
while($row = mysql_fetch_assoc($result)){
  $stuff .= "<option value=\"".$row['id']."\">".$row['phonename']."</option>";
} // end while for result set
$stuff .= "</select>";
echo $stuff;
mustafamisir
Forum Newbie
Posts: 23
Joined: Wed Jun 22, 2005 1:00 pm
Contact:

Post by mustafamisir »

I put the code but it id not work, can you check it again?
or maybe you give me another suggestion...
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

used "sample" table names and field names I did, no clue what your "real" stuff looks like I have.

difficult to troubleshoot your problem without more information it is.

1)provide your table structure you should
2)provide any errors you are getting you should

better able to help you we will be.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

and post what little code you have so far
mustafamisir
Forum Newbie
Posts: 23
Joined: Wed Jun 22, 2005 1:00 pm
Contact:

Post by mustafamisir »

Thank you for all answers. Mainly, a for loop solved the problem
Post Reply