Page 1 of 1

Popullating drop down menu - urgent

Posted: Wed Sep 15, 2010 6:25 am
by pokiaman
I m trying to get it work in php but i cant, since i m new in PHP :( i was wondering if someone can help and i would really appreciate it!!

Description:
In a php page i want to choose from a drop down menu (Houses) a choise for example a house and after that on a second drop down menu below to show me automatically the rooms of the house i choosed on the menu above..

I created 2 tables on a database houses_db in mysql
i. one table called houses with one column with house1, house2,...etc
ii. and on second table called rooms with first column called house1 and the rooms in it, second column house2 and the rooms in it and so on..

so on the php page when i select from the first menu a house on the second menu to show me the rooms that it has

i hope that was clear enough,,,i m sure this can be done with a mysql query but i dont kno how i write something but it doesnt work i m sure is wrong!!!!!i m confused on the use of the variables..

Code: Select all

<?php
$db = mysql_connect("localhost", "root", "password");

mysql_select_db("houses_db",$db);

?>
<select name=rooms>
<?php

$query = "SELECT houses, rooms from rooms";
$result = mysql_db_query($db, $query, $connection) or die ("Error in query: $query. " . mysql_error());
while (list($houses, $rooms) = mysql_fetch_row($result))
{
echo "<option value=$houses>$rooms</option>"; 
}
mysql_free_result($result);
?>
PLEASE HELP i m so confused!!!! :(

Re: Popullating drop down menu - urgent

Posted: Wed Sep 15, 2010 1:09 pm
by califdon
I really hate to say it like this, but you really need to learn the most basic things about relational databases before you attempt something like this that there's no point in trying to teach you in a forum like this. Read some tutorials and learn how to structure your tables (those are completely useless). Your problem is not populating drop down boxes, it's your understanding of how the database must be structured.