Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello ,

I am developing one project in php in which there are two tables as city(city_id, city_name) and hotel(hotel_id, city_id, hotel_name). The php page contains two drop down list in which 1st drop down list contains the list cities and 2nd drop down list contains the hotels in the selected city(from 1st drop down list)
Please help me for this project.
Posted
Comments
Nelek 1-Sep-13 16:18pm    
Please don't think we can read minds or do astral projections to see your monitor. If you need help, the least you could do is to add some relevant code to your question or to explain your problem in such a way, that the users of CP can understand it. Otherwise, nobody will be able to help you.

Since you didn't ask any question, it is difficult to give you a better answer.

I strongly recommend you to read:
How to ask a question[^] and What have you tried?[^]

1 solution

Firstly, get the value of the city. The value of the option should be the city ID. Then query the data base for the city_id in the hotel table, then return the results. E.g.

PHP
$cityId = $_POST['city']; // Get the city id from the drop down

$result = mysql_query("SELECT * FROM `hotel` WHERE `city_id` = '".$cityId."'"); // Query the data base for hotels containing the city_id

if($result) // Some error checking
{
     if(mysql_num_rows($result) == 0) // If there are no entries, say so
           echo "<option>There are no hotels!</option>";
     else
     {
           // Return all of the entries
           while($hotel = mysql_fetch_array($result)
           {
                echo "<option value="".$hotel["hotel_id"]."">".$hotel["hotel_name"]."</option>";
           }
     }
}
 
Share this answer
 
Comments
Nelek 1-Sep-13 16:18pm    
That's what I call telepathy.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900