Advertisement
Guest User

Untitled

a guest
Nov 27th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <HTML>
  2. <HEAD>
  3. <TITLE>
  4. <?php
  5. // show city if one is selected
  6. $city = $_REQUEST["city"];
  7. if($city)
  8. {
  9. echo $city;
  10. }
  11. ?>
  12. </TITLE>
  13. </HEAD>
  14.  
  15. <?php
  16.  
  17. $db_host = "host here";
  18.  
  19. $db_username = "username here";
  20.  
  21. $db_pass = "password here";
  22.  
  23. $db_name = "name of the db";
  24.  
  25.  
  26. mysql_connect("$db_host","$db_username","$db_pass") or die(mysql_error());
  27. mysql_select_db("$db_name") or die("no database by that name");
  28. ?>
  29. <P>
  30. <FORM ACTION= "pulldown_hotels.php" METHOD=GET>
  31. <P>
  32. Which city are you interested in?
  33. <BR>
  34. <BR>
  35. <select name=city size = 1>
  36. <option> -Select from below-
  37. <!-- fixed option is hint for dynamic -->
  38. <?php
  39. // fill pulldown with current city names from table
  40.  
  41. $query = $conn->prepare('SELECT distinct city FROM hotels order by city');
  42. $query->execute([':city' => $city]);
  43. $rows = $query->fetchAll(PDO::FETCH_OBJ); # Set this as a default, actually
  44.  
  45. if (!count($rows)) {
  46. die('<h1>ERROR – no rows returned</h1>');
  47. }
  48.  
  49. foreach ($rows as $row) {
  50. $city = $row->city;
  51.  
  52. ?>
  53.  
  54. <option> <?php echo $possible_city ?>
  55.  
  56. <?php
  57. //end loop through cities for pulldown results
  58. }
  59. ?>
  60. </select>
  61.  
  62.  
  63.  
  64.  
  65.  
  66. <BR>
  67. <BR>
  68. <INPUT TYPE=SUBMIT VALUE="Go">
  69. <INPUT TYPE=RESET>
  70.  
  71. </FORM>
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. <hr>
  80. <TABLE BORDER>
  81.  
  82. <?php
  83. // results part
  84. // Called for first time/no args just does the form above
  85. // Called with city produces output
  86.  
  87. if ($city) {
  88. # You should probably do this in one query using JOIN
  89. $query = $conn->prepare('SELECT * FROM hotels WHERE city = :city');
  90. $query->execute([':city' => $city]);
  91. $hotels = $query->fetchAll(PDO::FETCH_OBJ);
  92.  
  93. if (!count($hotels)) {
  94. die('<h1>ERROR – no rows returned</h1>');
  95. }
  96.  
  97.  
  98.  
  99. // end loop through hotel detail results
  100. }
  101. // end if ?>
  102. <TR>
  103. <TD>
  104. <b><?php echo $name ?></b></p>
  105. </TD>
  106. <TD>
  107. <?php echo $address, $city ?>
  108. </TD>
  109. <TD>
  110. <?php echo $stars ?>
  111. </TD>
  112. <TD>
  113. <?php echo $no_of_beds ?>
  114. </TD>
  115. <TD>
  116. <?php echo $rate ?>
  117. </TD>
  118. </TR>
  119.  
  120. <?php
  121.  
  122. ?>
  123.  
  124. </TABLE>
  125.  
  126. <?php
  127. // tidy up
  128. foreach ($hotels as $hotel) {
  129. mysql_close($conn);
  130.  
  131. }
  132. ?>
  133.  
  134.  
  135. </BODY>
  136. </HTML>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement