Advertisement
Guest User

Inner Join paste

a guest
Nov 29th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Results</title>
  4. </head>
  5. <body>
  6. <style>
  7. body {background-image: url("margarita cookies.jpg")}
  8. h1, p {text-align: center}
  9. table, th, td {
  10. border: 1px solid black;
  11. background-color:#e6ffcc;
  12. padding: 10px;
  13. }
  14. </style>
  15.  
  16. <body>
  17. <h1>Poisons</h1>
  18. <?php
  19. $host="localhost";
  20. $username="alcohaul";
  21. $password="drunk";
  22. $database="alcohaul";
  23. $link= mysqli_connect($host,$username,$password,$database);
  24. $type = $_GET['type'];
  25. $hh = $_GET['happy_hour'];
  26. $flavor = $_GET['flavor'];
  27. $area = $_GET['area'];
  28. $rest = $_GET['rest'];
  29.  
  30. $master = "SELECT master.master_id, rest.rest, marg.marg, area.area, flavor.flavor, type.type, happy_hour.hh FROM master";
  31.  
  32. if (isset($_GET['type']) && ($_GET['type']!== 'No preference')){
  33. $master.=" INNER JOIN type on master.type_id=$type";
  34. }
  35. if (isset($_GET['happy_hour']) && ($_GET['happy_hour'] !=='No preference')){
  36. $master.=" INNER JOIN happy_hour on master.hh_id=$hh";
  37. }
  38. if (isset($_GET['flavor']) && ($_GET['flavor'] !=='No preference')){
  39. $master.=" INNER JOIN flavor ON master.flavor_id=$flavor";
  40. }
  41. if (isset($_GET['area']) && ($_GET['area'] !=='No preference')){
  42. $master.=" INNER JOIN area ON master.area_id=$area";
  43. }
  44. if (isset($_GET['rest']) && ($_GET['rest'] !=='No preference')){
  45. $master.=" INNER JOIN rest ON master.rest_id=$rest";
  46. }
  47. $master.=" ORDER BY rest.rest, marg.marg";
  48. $result = $link->query($master);
  49.  
  50. if ($result->num_rows > 0) {
  51. echo "<table align=center><tr><th>Restaurant</th><th>Margarita Name</th><th>Area of Austin</th><th>Flavor</th><th>Consistency</th><th>Happy Hour?</th></tr>";
  52. // output data of each row
  53. while($row = $result->fetch_assoc()) {
  54. echo "<tr><td>".$row["rest"]."</td><td>".$row["marg"]."</td><td>".$row["area"]."</td><td>".$row["flavor"]."</td><td>".$row["type"]."</td><td>".$row["hh"]."</td></tr>";
  55. }
  56. echo "</table>";
  57. } else {
  58. echo "<h2>0 results. Stop being picky, all alcohol is good alcohol!</h2>";
  59. }
  60. $conn->close();
  61.  
  62. mysqli_close($link);
  63. ?>
  64.  
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement