Advertisement
Guest User

Untitled

a guest
Jan 26th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.87 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <title="Griff's Book Shop">
  4.   <head>
  5.         <style>
  6.           .titlebar {
  7.             width:1000px;
  8.             height:150px;
  9.             margin:auto;
  10.             border: 1px solid #000000;
  11.             font-size: 62;
  12.             text-align: center;
  13.           }
  14.           .mainarea {
  15.             width:1000px;
  16.             height:600px;
  17.             margin:auto;
  18.             border: 1px solid #000000;
  19.             overflow:scroll;
  20.           }
  21.           .titledetails {
  22.             width:1000px;
  23.             height:600px;
  24.             margin:auto;
  25.             border: 1px solid #000000;
  26.             overflow:scroll;
  27.             display: none;
  28.           }
  29.           .booktable {
  30.             width=100%;
  31.           }
  32.           .backbutton {
  33.             font-size: small;
  34.           }
  35.         </style>
  36.  
  37. <?php
  38. $servername = "localhost";
  39. $username = "xxxxxxxxx";
  40. $password = "xxxxxxxxx";
  41. $dbname = "griffbookshop";
  42.  
  43. // GET variables
  44.  
  45. $title=$_GET['book'];
  46. $author=$_GET['author'];
  47. $publisher=$_GET['publisher'];
  48. $genre=$_GET['genre'];
  49.  
  50. // Create connection
  51. $conn = new mysqli($servername, $username, $password, $dbname);
  52. // Check connection
  53. if ($conn->connect_error) {
  54.     die("Connection failed: " . $conn->connect_error);
  55. }
  56. ?>
  57.  
  58.   </head>
  59.   <body>
  60.         <div class="titlebar" id="titlebar" name="titlebar">
  61.                 Griff's BookShop <br />
  62.                 <a href="index.php"><span class="backbutton">Back to Index</span></a>
  63.         </div>
  64.  
  65.         <div class="mainarea" id="booklist" name="booklist">
  66.  
  67. <?php
  68. $sql = "SELECT * FROM books";
  69.  
  70. $result = $conn->query($sql);
  71.  
  72. echo "<form><table><tr><td><select id=dropdowntitles onchange=''>";
  73.  
  74. if ($result->num_rows > 0) {
  75. //     output data of each row
  76.        while($row = $result->fetch_assoc()) {
  77.         echo "<option value='". $row[Title] . "'>". $row[Title] . "</option>";
  78.     }
  79. } else {
  80.     echo "<option value='0 results'></option>";
  81. }
  82. echo "</select></td>";
  83.  
  84. echo "<td><select id=dropdownauthors onchange=''>";
  85.  
  86. $sql = "SELECT * FROM authors";
  87.  
  88. $result = $conn->query($sql);
  89.  
  90. if ($result->num_rows > 0) {
  91. //     output data of each row
  92.        while($row = $result->fetch_assoc()) {
  93.         echo "<option value='". $row[Author] . "'>". $row[Author] . "</option>";
  94.     }
  95. } else {
  96.     echo "<option value='0 results'></option>";
  97. }
  98.  
  99. echo "</select></td>";
  100.  
  101. echo "<td><select id=dropdownpublisher onchange=''>";
  102.  
  103. $sql = "SELECT * FROM publisher";
  104.  
  105. $result = $conn->query($sql);
  106.  
  107. if ($result->num_rows > 0) {
  108. //     output data of each row
  109.        while($row = $result->fetch_assoc()) {
  110.         echo "<option value='". $row[Publisher] . "'>". $row[Publisher] . "</option>";
  111.     }
  112. } else {
  113.     echo "<option value='0 results'></option>";
  114. }
  115.  
  116. echo "</select></td>";
  117.  
  118. echo "<td><select  id=dropdowngenre onchange=''>";
  119.  
  120. $sql = "SELECT * FROM genre";
  121.  
  122. $result = $conn->query($sql);
  123.  
  124. if ($result->num_rows > 0) {
  125. //     output data of each row
  126.        while($row = $result->fetch_assoc()) {
  127.         echo "<option value='". $row[Genre] . "'>". $row[Genre] . "</option>";
  128.     }
  129. } else {
  130.     echo "<option value='0 results'></option>";
  131. }
  132.  
  133. echo "</select></td></tr></table></form>";
  134.  
  135. if ($book != '') {
  136. echo "Book Selected - " . $title;
  137. $sql = "SELECT b.BookID,b.Title,a.Author,g.Genre,f.Fictional,p.Publisher FROM books b JOIN authors a ON a.AuthorId=b.BookId JOIN genre g ON g.GenreId=b.GenreID JOIN fictional f ON f.FictionalID=b.FictionalID JOIN publisher p on p.PublisherID=b.PublisherID WHERE b.Title='" . str_replace('_',' ',$title) . "'";
  138. } elseif ($author != '') {
  139. echo "Author Selected - " . $author;
  140. $sql = "SELECT b.BookID,b.Title,a.Author,g.Genre,f.Fictional,p.Publisher FROM books b JOIN authors a ON a.AuthorId=b.BookId JOIN genre g ON g.GenreId=b.GenreID JOIN fictional f ON f.FictionalID=b.FictionalID JOIN publisher p on p.PublisherID=b.PublisherID WHERE a.Author='" . str_replace('_',' ',$author) . "'";
  141. } elseif ($publisher != '') {
  142. echo "Publisher Selected - " . $publisher;
  143. $sql = "SELECT b.BookID,b.Title,a.Author,g.Genre,f.Fictional,p.Publisher FROM books b JOIN authors a ON a.AuthorId=b.BookId JOIN genre g ON g.GenreId=b.GenreID JOIN fictional f ON f.FictionalID=b.FictionalID JOIN publisher p on p.PublisherID=b.PublisherID WHERE p.Publisher='" . str_replace('_',' ',$publisher) . "'";
  144. } elseif ($genre != '') {
  145. echo "Genre Selected - " . $genre;
  146. $sql = "SELECT b.BookID,b.Title,a.Author,g.Genre,f.Fictional,p.Publisher FROM books b JOIN authors a ON a.AuthorId=b.BookId JOIN genre g ON g.GenreId=b.GenreID JOIN fictional f ON f.FictionalID=b.FictionalID JOIN publisher p on p.PublisherID=b.PublisherID WHERE g.genre='" . str_replace('_',' ',$genre) . "'";
  147. } else {
  148. echo "Nothing selected!";
  149. $sql = "SELECT b.BookID,b.Title,a.Author,g.Genre,f.Fictional,p.Publisher FROM books b JOIN authors a ON a.AuthorId=b.BookId JOIN genre g ON g.GenreId=b.GenreID JOIN fictional f ON f.FictionalID=b.FictionalID JOIN publisher p on p.PublisherID=b.PublisherID";
  150. }
  151.  
  152. $result = $conn->query($sql);
  153.  
  154.  
  155. echo "<table class='booktable' id='booktable'><tr class='bookheader' id='bookheader'><td><b>Title</b></td><td><b>Author</b></td><td><b>Publisher</b></td><td><b>Genre</b></td></tr>";
  156.  
  157. if ($result->num_rows > 0) {
  158. //     output data of each row
  159.        while($row = $result->fetch_assoc()) {
  160.         echo "
  161.  
  162. <tr>
  163. <td>" . $row["Title"] . "</td>
  164. <td><a href=index.php?author=" . str_replace(' ','_',$row['Author']) . ">" . $row["Author"] . "</a></td>
  165. <td><a href=index.php?publisher=" . str_replace(' ','_',$row['Publisher']) . ">" . $row["Publisher"] . "</a></td>
  166. <td><a href=index.php?genre=" . str_replace(' ','_',$row['Genre']) . ">" . $row["Genre"] . "</a></td>
  167. </tr>
  168. ";
  169.  
  170.     }
  171. } else {
  172.     echo "0 results";
  173. }
  174.  
  175. //$echo "</table>";
  176.  
  177. $conn->close();
  178. ?>
  179.  
  180.         </div>
  181.  
  182. <div class="titledetails" id="titledetails">
  183.         sdfsfdsfd
  184. </div>
  185.   </body>
  186. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement