Page 1 of 1

Create a Drop Down List with PHP

Posted: Wed Jun 22, 2005 1:10 pm
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...

Posted: Wed Jun 22, 2005 1:26 pm
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;

Posted: Wed Jun 22, 2005 1:38 pm
by mustafamisir
I put the code but it id not work, can you check it again?
or maybe you give me another suggestion...

Posted: Wed Jun 22, 2005 1:42 pm
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.

Posted: Wed Jun 22, 2005 2:06 pm
by shiznatix
and post what little code you have so far

Posted: Wed Jun 22, 2005 3:10 pm
by mustafamisir
Thank you for all answers. Mainly, a for loop solved the problem