Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <HTML>
- <HEAD>
- <TITLE>
- <?php
- // show city if one is selected
- $city = $_REQUEST["city"];
- if($city)
- {
- echo $city;
- }
- ?>
- </TITLE>
- </HEAD>
- <?php
- $db_host = "host here";
- $db_username = "username here";
- $db_pass = "password here";
- $db_name = "name of the db";
- mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error());
- mysql_select_db("$db_name") or die("no database by that name");
- ?>
- <P>
- <FORM ACTION= "pulldown_hotels.php" METHOD=GET>
- <P>
- Which city are you interested in?
- <BR>
- <BR>
- <select name=city size = 1>
- <option> -Select from below-
- <!-- fixed option is hint for dynamic -->
- <?php
- // fill pulldown with current city names from table
- $query = $conn->prepare('SELECT distinct city FROM hotels order by city');
- $query->execute([':city' => $city]);
- $rows = $query->fetchAll(PDO::FETCH_OBJ); # Set this as a default, actually
- if (!count($rows)) {
- die('<h1>ERROR – no rows returned</h1>');
- }
- foreach ($rows as $row) {
- $city = $row->city;
- ?>
- <option> <?php echo $possible_city ?>
- <?php
- //end loop through cities for pulldown results
- }
- ?>
- </select>
- <BR>
- <BR>
- <INPUT TYPE=SUBMIT VALUE="Go">
- <INPUT TYPE=RESET>
- </FORM>
- <hr>
- <TABLE BORDER>
- <?php
- // results part
- // Called for first time/no args just does the form above
- // Called with city produces output
- if ($city) {
- # You should probably do this in one query using JOIN
- $query = $conn->prepare('SELECT * FROM hotels WHERE city = :city');
- $query->execute([':city' => $city]);
- $hotels = $query->fetchAll(PDO::FETCH_OBJ);
- if (!count($hotels)) {
- die('<h1>ERROR – no rows returned</h1>');
- }
- // end loop through hotel detail results
- }
- // end if ?>
- <TR>
- <TD>
- <b><?php echo $name ?></b></p>
- </TD>
- <TD>
- <?php echo $address, $city ?>
- </TD>
- <TD>
- <?php echo $stars ?>
- </TD>
- <TD>
- <?php echo $no_of_beds ?>
- </TD>
- <TD>
- <?php echo $rate ?>
- </TD>
- </TR>
- <?php
- ?>
- </TABLE>
- <?php
- // tidy up
- foreach ($hotels as $hotel) {
- mysql_close($conn);
- }
- ?>
- </BODY>
- </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement