Advertisement
Guest User

Untitled

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