Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.11 KB | None | 0 0
  1. <?php
  2. // load DB
  3. require('Database.class.php');
  4. $database = new Database();
  5.  
  6. ?>
  7.  
  8. <!DOCTYPE html>
  9.  
  10. <html>
  11.  
  12. <head>
  13. <meta charset="UTF-8">
  14. <title>Las Vegas Summer Poker Tour</title>
  15. <style>
  16. table, th, td {
  17. border: 1px solid black;
  18. }
  19. </style>
  20.  
  21. </head>
  22.  
  23. <body>
  24.  
  25. <h1>2019 Las Vegas Poker Donkfest</h1>
  26.  
  27. <h1>Sort by Casino Name</h1>
  28.  
  29. <form action="index.php" method="post">
  30.  
  31. <!-- it's good to have labels for your form elements -->
  32. <label for="casinoName">Choose your casino</label>
  33. <br>
  34.  
  35. <select id="casinoName" name="casinoName">
  36. <!-- set the default "all" option to 0 so if they pick all it comes through as just "0" and is easier to work with -->
  37. <option value="0">-All-</option>
  38.  
  39. <?php
  40. // get casino names
  41. $casinoNames = $database->getCasinoNames();
  42. // selected casino name if they submitted the form
  43. $selectedCasino = isset($_POST['casinoName']) ? $_POST['casinoName'] : '';
  44.  
  45. // loop through the casino names
  46. foreach ($casinoNames as $casinoName) {
  47. // here we will add selected to the <option> html tag if this is our selected casino
  48. // this way the dropdown doesn't reset every time we submit the form
  49. $selected = ($selectedCasino == $casinoName) ? 'selected' : '';
  50. echo "<option value=\"$casinoName\" $selected>$casinoName</option>";
  51. }
  52. ?>
  53. <?php
  54. // get casino dates
  55. $casinoDates = $database->getCasinoDates();
  56. // selected casino date if they submitted the form
  57. $selectedDates = isset($_POST['casinoDate']) ? $_POST['casinoDate'] : '';
  58.  
  59. // loop through the casino dates
  60. foreach ($casinoDates as $casinoDate) {
  61. // here we will add selected to the <option> html tag if this is our selected casino
  62. // this way the dropdown doesn't reset every time we submit the form
  63. $selected = ($selectedDates == $casinoDate) ? 'selected' : '';
  64.  
  65. }
  66. ?>
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. </select>
  74.  
  75.  
  76.  
  77. <input type="date"
  78. name="casinoDate"
  79. value="<?php echo (isset($_POST['casinoDate']) ? $_POST['casinoDate'] : ''); ?>"
  80. min="2018-05-25"
  81. max="2018-07-01">
  82.  
  83. <button id="filter">Search</button>
  84. <br>
  85.  
  86. </form>
  87.  
  88.  
  89.  
  90. <div>
  91. <?php
  92.  
  93. // an example showing we know what was selected
  94. // we can do an if here because $selectedCasino will be null if nothing was submitted
  95. // or 0 if they picked -ALL-
  96. // null and 0 are both evaluated as false in an if, so this only runs if they picked an actual casino
  97. if ($selectedCasino) {
  98. echo "You chose $selectedCasino!";
  99. }
  100. ?>
  101.  
  102. <?php
  103. $servername = "localhost";
  104. $username = "root";
  105. $password = "";
  106. $dbname = "vegaspoker";
  107.  
  108. $conn = new mysqli($servername, $username, $password, $dbname);
  109.  
  110. if ($conn->connect_error) {
  111. die("Connection Failed: " . $conn->connect_error);
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118. // load html table
  119.  
  120. $sql = "SELECT * FROM tournaments WHERE true";
  121. if(isset($_POST['casinoName'])) {
  122. $sql .= " and casino = '" . $_POST['casinoName'] . "'";
  123. }
  124. if(isset($_POST['casinoDate'])) {
  125. $sql .= " and schedule = '" . $_POST['casinoDate'] . "'";
  126. }
  127.  
  128.  
  129.  
  130.  
  131. $result = $conn->query($sql);
  132. if($result == mysqli_query($conn, $sql)){
  133. if(mysqli_num_rows($result) > 0){
  134. echo "<table>";
  135. echo "<tr>";
  136. echo "<th>id</th>";
  137. echo "<th>grouping</th>";
  138. echo "<th>casino</th>";
  139. echo "<th>cost</th>";
  140. echo "<th>game</th>";
  141. echo "<th>schedule</th>";
  142. echo "<th>fee_percent</th>";
  143. echo "<th>s_points</th>";
  144. echo "<th>notes</th>";
  145. echo "</tr>";
  146.  
  147. if($result->num_rows > 0) {
  148.  
  149. while($row = $result->fetch_assoc()) {
  150. echo "<tr>";
  151. echo "<td>" . $row["id"]. "</td>";
  152. echo "<td>".$row["grouping"]."</td>";
  153. echo "<td>" . $row["casino"]. "</td>";
  154. echo "<td>". $row["cost"]. "</td>";
  155. echo "<td>". $row["game"]. "</td>";
  156. echo "<td>". $row["schedule"]."</td>";
  157. echo "<td>". $row["fee_percent"]."</td>";
  158. echo "<td>". $row["s_points"]."</td>";
  159. echo "<td>". $row["notes"]."</tr>";
  160. echo "</tr>";
  161.  
  162.  
  163. }
  164.  
  165. }
  166. }
  167. }
  168.  
  169. ?>
  170. </div>
  171.  
  172. </body>
  173. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement