Advertisement
Guest User

index002

a guest
Apr 28th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.40 KB | None | 0 0
  1. <!--PHP BLOCK-->
  2. <?php
  3.  
  4. $query2 = "SELECT * FROM LOCATIONS";
  5. $all_locations = filterTable($query2);
  6.  
  7. $query3 = "SELECT * FROM PERFORMERS";
  8. $all_bands = filterTable($query3);
  9.  
  10. // Default Error message
  11. $errorMessage = "There are no show times for the band / venue you selected!";
  12.  
  13. // If we are searching the database
  14. if(isset($_POST['submitVal']))
  15. {
  16.     // Get the values from the search form
  17.     $searchColumn = $_POST['selectVal'];
  18.     $searchData = $_POST['searchVal'];
  19.  
  20.     // Check if dropdown was selected and text was entered
  21.     $validate = (!$searchData == "");
  22.  
  23.     if ($validate) {
  24.  
  25.         // Table to search from
  26.         if ($searchColumn == "Venue" || $searchColumn ==  "City" || $searchColumn ==  "State") {
  27.             $searchTable = "LOCATIONS";
  28.         }
  29.         else {
  30.             $searchTable = "PERFORMERS";
  31.         }
  32.  
  33.         // Perform a query search based on the two searched values
  34.         $query1 = "SELECT LOCATIONS.Venue AS \"Venue\",
  35.                         CONCAT(LOCATIONS.City, \", \", LOCATIONS.State) AS \"Location\",
  36.                         PERFORMERS.BandName AS \"Band\",
  37.                         PERFORMERS.Genre AS \"Genre\",
  38.                         PERFORMERS.Album_Showing AS \"Album\",
  39.                         SHOWS.Showtime AS \"Show Time\"
  40.                  FROM SHOWS INNER JOIN PERFORMERS ON SHOWS.BandId = PERFORMERS.BandId
  41.                       INNER JOIN LOCATIONS ON SHOWS.LocationId=LOCATIONS.LocationId
  42.                       WHERE $searchTable.$searchColumn = \"$searchData\";";
  43.  
  44.         $queryResults = filterTable($query1);
  45.     }
  46.     else
  47.     {
  48.         $query1 = "SELECT * FROM UPCOMING_EVENTS WHERE Location = -1;";
  49.         $queryResults = filterTable($query1);
  50.     }
  51.  
  52. }
  53. // we are not searching, get everything from the database
  54. else {
  55.     $query1 = "SELECT * FROM UPCOMING_EVENTS WHERE Location = -1;";
  56.     $queryResults = filterTable($query1);
  57. }
  58.  
  59. // function to connect and execute the query
  60. function filterTable($query)
  61. {
  62.     // 1. Create a database connection
  63.     $dbhost = "ecsmysql";
  64.     $dbuser = "cs332u4";  // where ?? is your id
  65.     $dbpass = "laiximuk"; // replace with your password
  66.     $dbname = "cs332u4";
  67.     $dbconnection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  68.  
  69.     // 2. Check if the connection is ok
  70.     if (mysqli_connect_errno()) {
  71.         die("Database connection failed: " .
  72.             mysqli_connect_error() . " (" > mysqli_connect_errno() . ")" );
  73.     }
  74.  
  75.     // 3. Execute the query
  76.     $filter_Result = mysqli_query($dbconnection, $query);
  77.  
  78.     // Check if there is a query error
  79.     if (!$filter_Result) {
  80.         die("Database query \"$query\" failed.");
  81.     }
  82.  
  83.     // Return the query result
  84.     return $filter_Result;
  85.  
  86.     $dbconnection->close();
  87. }
  88. ?>
  89. <!--END OF PHP BLOCK-->
  90.  
  91.  
  92. <!--HTML BLOCK-->
  93. <!DOCTYPE html>
  94. <html>
  95. <head>
  96.     <title>Show Times Search!</title>
  97.     <style type="text/css">
  98.         /* Begin Styled HTML Table */
  99.         .tftable {font-size:12px;color:#333333;border-width:1px;border-color:#729ea5;border-collapse:collapse;float:left;}
  100.         .tftable th {font-size:12px;background-color:#acc8cc;border-width:1px;padding:8px;border-style:solid;border-color:#729ea5;text-align:left;}
  101.         .tftable tr {background-color:#ffffff;}
  102.         .tftable td {font-size:12px;border-width:1px;padding:8px; border-style:solid;border-color:#729ea5;}
  103.         .tftable table{float: left; table-layout: fixed;}
  104.     </style>
  105. </head>
  106.  
  107. <body>
  108.  
  109. <!--Search Form-->
  110. <form method="post">
  111.  
  112.     <!--Dropdown List    -->
  113.     <select name="selectVal">
  114.         <option value="BandName">Band Name</option>
  115.         <option value="Genre">Genre</option>
  116.         <option value="Venue">Venue</option>
  117.         <option value="City">City</option>
  118.         <option value="State">State</option>
  119.     </select>
  120.  
  121.     <!--Edit text box-->
  122.     <input type='text' name='searchVal' placeholder='Enter text here...' size='50'><br>
  123.  
  124.     <!--Sumbit Button-->
  125.     <input type="submit" name="submitVal" value="Filter"><br><br>
  126.    
  127.     <div>
  128.         <!--Band Table-->
  129.         <table class="tftable" border="1">
  130.             <tr>
  131.                 <th>BandId</th>
  132.                 <th>Band</th>
  133.                 <th>Genre</th>
  134.             </tr>
  135.  
  136.             <!-- Populate table from mysql database -->
  137.             <?php while($row = mysqli_fetch_array($all_bands)):?>
  138.                 <tr>
  139.                     <td><?php echo $row['BandId'];?></td>
  140.                     <td><?php echo $row['BandName'];?></td>
  141.                     <td><?php echo $row['Genre'];?></td>
  142.                 </tr>
  143.             <?php endwhile;?>
  144.         </table>
  145.  
  146.         <!--Locations Table-->
  147.         <table class="tftable" border="1">
  148.             <tr>
  149.                 <th>Location Id</th>
  150.                 <th>Venue</th>
  151.                 <th>City</th>
  152.                 <th>State</th>
  153.             </tr>
  154.  
  155.             <!-- Populate table from mysql database -->
  156.             <?php while($row = mysqli_fetch_array($all_locations)):?>
  157.                 <tr>
  158.                     <td><?php echo $row['LocationId'];?></td>
  159.                     <td><?php echo $row['Venue'];?></td>
  160.                     <td><?php echo $row['City'];?></td>
  161.                     <td><?php echo $row['State'];?></td>
  162.                 </tr>
  163.             <?php endwhile;?>
  164.         </table>
  165.     </div>
  166.  
  167.     <br><br><br>
  168.     <br><br><br>
  169.     <br><br><br>
  170.     <br><br><br>
  171.     <br><br><br>
  172.     <br>
  173.     <br><br><br>
  174.     <br>
  175.  
  176.     <!--Upcoming Events Resuls-->
  177.     <?php if(mysqli_num_rows($queryResults) > 0):?>
  178.         Below are the Show Times for your band and venue!
  179.        
  180.         <div>
  181.             <table class="tftable" border="1">
  182.                 <tr>
  183.                     <th>Venue</th>
  184.                     <th>Location</th>
  185.                     <th>Band</th>
  186.                     <th>Album</th>
  187.                     <th>Show Time</th>
  188.                 </tr>
  189.  
  190.                 <?php while($row = mysqli_fetch_array($queryResults)):?>
  191.                 <tr>
  192.                     <td><?php echo $row['Venue'];?></td>
  193.                     <td><?php echo $row['Location'];?></td>
  194.                     <td><?php echo $row['Band'];?></td>
  195.                     <td><?php echo $row['Album'];?></td>
  196.                     <td><?php echo $row['Show Time'];?></td>
  197.                 </tr>
  198.                 <?php endwhile;?>
  199.             </table>
  200.         </div>
  201.     <?php else :?>
  202.         <?php echo $errorMessage ?>
  203.     <?php endif;?>
  204.     </table>
  205. </form>
  206.  
  207. </body>
  208.  
  209.  
  210. <!--Cleanup-->
  211. <?php
  212. // 4. Release returned result
  213. mysqli_free_result($queryResults);
  214. mysqli_free_result($all_bands);
  215. mysqli_free_result($all_locations);
  216. ?>
  217.  
  218. </html>
  219. <!--END OF HTML BLOCK-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement