Dropdown list to query database and show results

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
tom8521
Forum Commoner
Posts: 25
Joined: Thu May 13, 2010 6:24 am

Dropdown list to query database and show results

Post by tom8521 »

How can I use a dropdown list to query a database and return the results. This only needs to be simple by the way, nothing too advanced.

The information in the dropdown list should be named 'Prop_type' and will be getting information from the 'property' table. If someone knows how to do this, please help me. I don't think it is overly techy for all you brainiacs.

Thanks in advance! :D
Tom.
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: Dropdown list to query database and show results

Post by roders »

query the database as you would normally do.
Create your dropdown as you would normal create, then your <option> tags should be included inside the while loop of the query e.g.

Code: Select all

$query="select * from table";
$result=mysql_quer($result);
while($row=mysql_fetch_array($result))
{
    echo "<option value=\"".$row['fieldnamevalue']."\">".$row['fieldnamedescription']."</option>";
}
tom8521
Forum Commoner
Posts: 25
Joined: Thu May 13, 2010 6:24 am

Re: Dropdown list to query database and show results

Post by tom8521 »

I still don't understand this.

I use a form to post these details:

Prop_beds
Prop_type
Prop_location

I need each to be checked alongside the 'property' table within the database. Help?
Post Reply