Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Results</title>
  4. </head>
  5. <body>
  6. <!-- make it look pretty --!>
  7. <style type="text/css">
  8. body {background-image: url("http://www.glorioustreats.com/wp-content/uploads/2011/06/Margarita-Cookies.jpg")}
  9. h1 {
  10. font-family: arial, sans-serif;
  11. text-align: center;
  12. }
  13. h2 {
  14. font-family: arial, sans-serif;
  15. text-align: left;
  16. padding: 10 0 0 20;
  17. font-size: 20px;
  18. }
  19. h3 {
  20. font-family: arial, sans-serif;
  21. text-align: left;
  22. padding: 10 0 0 20;
  23. font-size: 18px;
  24. }
  25. h4 {
  26. font-family: arial, sans-serif;
  27. text-align: left;
  28. padding: 10 0 0 20;
  29. font-size: 18px;
  30. color: #228B22;
  31. }
  32. p {
  33. font-family: arial, sans-serif;
  34. padding: 10 0 0 20;
  35. }
  36.  
  37. table {
  38. max-width: 1000px;
  39. padding: 10px 20px;
  40. background: #f4f7f8;
  41. margin: 10px auto;
  42. padding: 20px;
  43. background: #f4f7f8;
  44. border-radius: 8px;
  45. font-family: arial, sans-serif;
  46. }
  47. table.primary tr:nth-child(odd) {
  48. background-color: #c9e7a3;
  49. }
  50. table.primary tr:nth-child(even) {
  51. background-color: #f4f7f8;
  52. }
  53. table.primary tr.new {
  54. background-color: #f4f7f8;
  55. }
  56. .inlineTable {
  57. float:left;
  58. }
  59. td, th {
  60. text-align: center;
  61. padding: 8px;
  62. }
  63. .form-style-5{
  64. max-width: 500px;
  65. padding: 10px 20px;
  66. background: #f4f7f8;
  67. margin: 10px auto;
  68. padding: 20px;
  69. background: #f4f7f8;
  70. border-radius: 8px;
  71. font-family: arial, sans-serif;
  72. }
  73. .form-style-5 fieldset{
  74. border: none;
  75. }
  76. .form-style-5 legend {
  77. font-size: 1.4em;
  78. margin-bottom: 10px;
  79. }
  80. .form-style-5 label {
  81. display: block;
  82. margin-bottom: 8px;
  83. }
  84.  
  85. .form-style-5 select {
  86. font-family: arial, sans-serif;
  87. background: rgba(255,255,255,.1);
  88. border: none;
  89. border-radius: 4px;
  90. font-size: 16px;
  91. margin: 0;
  92. outline: 0;
  93. padding: 7px;
  94. width: 100%;
  95. box-sizing: border-box;
  96. -webkit-box-sizing: border-box;
  97. -moz-box-sizing: border-box;
  98. background-color: #e8eeef;
  99. color:#8a97a0;
  100. -webkit-box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
  101. box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
  102. margin-bottom: 30px;
  103.  
  104. }
  105.  
  106. .form-style-5 select:focus{
  107. background: #d2d9dd;
  108. }
  109. .form-style-5 select{
  110. -webkit-appearance: menulist-button;
  111. height:35px;
  112. }
  113. .form-style-5 .number {
  114. background: #1abc9c;
  115. color: #fff;
  116. height: 30px;
  117. width: 30px;
  118. display: inline-block;
  119. font-size: 0.8em;
  120. margin-right: 4px;
  121. line-height: 30px;
  122. text-align: center;
  123. text-shadow: 0 1px 0 rgba(255,255,255,0.2);
  124. border-radius: 15px 15px 15px 0px;
  125. }
  126.  
  127. .form-style-5 input[type="submit"],
  128. .form-style-5 input[type="button"]
  129. {
  130. position: relative;
  131. display: block;
  132. padding: 19px 39px 18px 39px;
  133. color: #FFF;
  134. margin: 0 auto;
  135. background: #1abc9c;
  136. font-size: 18px;
  137. text-align: center;
  138. font-style: normal;
  139. width: 100%;
  140. border: 1px solid #16a085;
  141. border-width: 1px 1px 3px;
  142. margin-bottom: 10px;
  143. }
  144. .form-style-5 input[type="submit"]:hover,
  145. .form-style-5 input[type="button"]:hover
  146. {
  147. background: #109177;
  148. }
  149.  
  150.  
  151. </style>
  152.  
  153. <body>
  154. <?php
  155. // set up connection to the database
  156. $host="localhost";
  157. $username="alcohaul";
  158. $password="drunk";
  159. $database="alcohaul";
  160. // set up variable to connect to the database
  161. $link= mysqli_connect($host,$username,$password,$database);
  162. // get data from the form and sanitize inputs
  163. $type = preg_replace("/[^ 0-9a-zA-Z]+/", "", $_GET['type']);
  164. $hh = preg_replace("/[^ 0-9a-zA-Z]+/", "", $_GET['happy_hour']);
  165. $flavor = preg_replace("/[^ 0-9a-zA-Z]+/", "", $_GET['flavor']);
  166. $area = preg_replace("/[^ 0-9a-zA-Z]+/", "", $_GET['area']);
  167. $rest = preg_replace("/[^ 0-9a-zA-Z]+/", "", $_GET['rest']);
  168.  
  169. // master select statement that includes joins
  170. $master = "SELECT master.master_id, rest.rest, marg.marg, area.area, flavor.flavor, type.type, happy_hour.hh FROM master LEFT JOIN marg ON master.marg_id=marg.marg_id LEFT JOIN rest ON master.rest_id=rest.rest_id LEFT JOIN area ON master.area_id=area.area_id LEFT JOIN flavor ON master.flavor_id=flavor.flavor_id LEFT JOIN type on master.type_id=type.type_id LEFT JOIN happy_hour on master.hh_id=happy_hour.hh_id";
  171.  
  172. // if all fields are set... add filters for all fields
  173. if ((isset($_GET['type']) && $_GET['type'] !== 'No preference') ||
  174. (isset($_GET['happy_hour']) && $_GET['happy_hour'] !=='No preference') ||
  175. (isset($_GET['flavor']) && $_GET['flavor'] !== 'No preference') ||
  176. (isset($_GET['area']) && $_GET['area'] !== 'No preference') ||
  177. (isset($_GET['rest']) && $_GET['rest'] !== 'No preference')) {
  178. $master.=" WHERE";
  179. }
  180. // add type
  181. if (isset($_GET['type']) && $_GET['type'] !== 'No preference') {
  182. $master.=" type.type_id=$type";
  183. if ((isset($_GET['happy_hour']) && $_GET['happy_hour'] !=='No preference') ||
  184. (isset($_GET['flavor']) && $_GET['flavor'] !=='No preference') ||
  185. (isset($_GET['area']) && $_GET['area'] !== 'No preference') ||
  186. (isset($_GET['rest']) && $_GET['rest'] !== 'No preference')) {
  187. $master.=" AND";
  188. }
  189. }
  190. //add happy hour
  191. if (isset($_GET['happy_hour']) && $_GET['happy_hour'] !=='No preference'){
  192. $master.=" happy_hour.hh_id=$hh";
  193. if ((isset($_GET['flavor']) && $_GET['flavor'] !== 'No preference') ||
  194. (isset($_GET['area']) && $_GET['area'] !== 'No preference') ||
  195. (isset($_GET['rest']) && $_GET['rest'] !== 'No preference')) {
  196. $master.=" AND";
  197. }
  198. }
  199. // add flavor
  200. if (isset($_GET['flavor']) && $_GET['flavor'] !== 'No preference'){
  201. $master.=" flavor.flavor_id=$flavor";
  202. if ((isset($_GET['area']) && $_GET['area'] !== 'No preference') ||
  203. (isset($_GET['rest']) && $_GET['rest'] !== 'No preference')){
  204. $master.=" AND";
  205. }
  206. }
  207. // add area
  208. if (isset($_GET['area']) && $_GET['area'] !=='No preference'){
  209. $master.=" area.area_id=$area";
  210. if (isset($_GET['rest']) && $_GET['rest'] !== 'No preference'){
  211. $master.=" AND";
  212. }
  213. }
  214. // add restaurant
  215. if (isset($_GET['rest']) && $_GET['rest'] !== 'No preference'){
  216. $master.=" rest.rest_id=$rest";
  217. }
  218. // order the margs
  219. $master.=" ORDER BY rest.rest, marg.marg";
  220. $result = $link->query($master);
  221.  
  222. // if results >0... print table of results
  223. if ($result->num_rows > 0) {
  224. echo "<table class='primary'><tr class='new';><th colspan='6'><h1>Your Poison</h1></th></tr><tr class='new';><th colspan='6'><form method=GET action='marg.php' class='form-style-5'></select><input type='submit' value='Back to Search'></h3></form></th></tr><tr class='new';><th>Restaurant</th><th>Margarita Name</th><th>Area of Austin</th><th>Flavor</th><th>Consistency</th><th>Happy Hour Availability</th></tr>";
  225. // output data of each row
  226. while($row = $result->fetch_assoc()) {
  227. 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>";
  228.  
  229. }
  230. echo "</table>";
  231. } else {
  232. // if no results are yeilded from search query, error message
  233. echo "0 results. Stop being picky, all alcohol is good alcohol!";
  234. }
  235. $conn->close();
  236.  
  237.  
  238. // close link to mysql database
  239. mysqli_close($link);
  240. ?>
  241.  
  242. </body>
  243. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement