Advertisement
Guest User

Untitled

a guest
Jan 26th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.53 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.           .booktable {
  22.             width=100%;
  23.           }
  24.           .bookheader {
  25.           }
  26.         </style>
  27.  
  28.   </head>
  29.   <body>
  30.         <div class="titlebar" id="titlebar" name="titlebar">
  31.                 Griff's BookShop
  32.         </div>
  33.  
  34.         <div class="mainarea" id="booklist" name="booklist">
  35.  
  36. <?php
  37. $servername = "localhost";
  38. $username = "xxxxxxxx";
  39. $password = "xxxxxxxx";
  40. $dbname = "griffbookshop";
  41.  
  42. // GET variables
  43.  
  44. $book=$_GET['book'];
  45. $author=$_GET['author'];
  46.  
  47. // Create connection
  48. $conn = new mysqli($servername, $username, $password, $dbname);
  49. // Check connection
  50. if ($conn->connect_error) {
  51.     die("Connection failed: " . $conn->connect_error);
  52. }
  53.  
  54. $sql = "SELECT * FROM books";
  55.  
  56. $result = $conn->query($sql);
  57.  
  58. echo "<form><table><tr><td><select>";
  59.  
  60. if ($result->num_rows > 0) {
  61. //     output data of each row
  62.        while($row = $result->fetch_assoc()) {
  63.         echo "<option value='". $row[Title] . "'>". $row[Title] . "</option>";
  64.     }
  65. } else {
  66.     echo "<option value='0 results'></option>";
  67. }
  68. echo "</select></td>";
  69.  
  70. echo "<td><select>";
  71.  
  72. $sql = "SELECT * FROM authors";
  73.  
  74. $result = $conn->query($sql);
  75.  
  76. if ($result->num_rows > 0) {
  77. //     output data of each row
  78.        while($row = $result->fetch_assoc()) {
  79.         echo "<option value='". $row[Author] . "'>". $row[Author] . "</option>";
  80.     }
  81. } else {
  82.     echo "<option value='0 results'></option>";
  83. }
  84. echo "</select></td></tr></table></form>";
  85.  
  86. if ($book != '') {
  87. echo "Book Selected - " . $book;
  88. $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";
  89. } elseif ($author != '') {
  90. echo "Author Selected - " . $author;
  91. $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) . "'";
  92. } else {
  93. echo "Nothing selected!";
  94. $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";
  95. }
  96.  
  97. $result = $conn->query($sql);
  98.  
  99.  
  100. echo "<table class='booktable' id='booktable'><tr class='bookheader' id='bookheader'><td><b>Title</b></td><td><b>Author</b></td></tr>";
  101.  
  102. if ($result->num_rows > 0) {
  103. //     output data of each row
  104.        while($row = $result->fetch_assoc()) {
  105.         echo "
  106.  
  107. <tr><td><a href=index.php?book=" . str_replace(' ','_',$row['Title']) . ">" . $row["Title"] . "</a></td>
  108. <td><a href=index.php?author=" . str_replace(' ','_',$row['Author']) . ">" . $row["Author"] . "</a></td></tr>";
  109.  
  110.     }
  111. } else {
  112.     echo "0 results";
  113. }
  114.  
  115. //$echo "</table>";
  116.  
  117. $conn->close();
  118. ?>
  119.  
  120.         </div>
  121.   </body>
  122. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement