| 40 | |
| 41 | {{{#!sql |
| 42 | //Similar Books |
| 43 | $stmt = $conn->prepare("SELECT book.bookid, coverimage, title, genre, firstname, lastname FROM book |
| 44 | INNER JOIN book_author ON book.bookid = book_author.bookid |
| 45 | INNER JOIN author ON book_author.authorid = author.authorid |
| 46 | WHERE book.genre = :bookgenre AND book.bookid != :bookid LIMIT 5; |
| 47 | "); |
| 48 | $stmt->bindParam(':bookgenre', $book_genre, PDO::PARAM_STR); |
| 49 | $stmt->bindParam(':bookid', $bookid, PDO::PARAM_INT); |
| 50 | // Execute the query |
| 51 | $stmt->execute(); |
| 52 | $similar_books = []; |
| 53 | |
| 54 | while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { |
| 55 | $similar_books[] = $row; |
| 56 | } |
| 57 | |
| 58 | //More Author |
| 59 | $stmt = $conn->prepare("SELECT book.bookid, coverimage, title, genre, firstname, lastname |
| 60 | FROM book |
| 61 | INNER JOIN book_author ON book.bookid = book_author.bookid |
| 62 | INNER JOIN author ON book_author.authorid = author.authorid |
| 63 | WHERE book_author.authorid IN ( |
| 64 | SELECT book_author.authorid |
| 65 | FROM book_author |
| 66 | WHERE book_author.bookid = :bookid |
| 67 | ) AND book.bookid != :bookid |
| 68 | LIMIT 5; |
| 69 | "); |
| 70 | $stmt->bindParam(':bookid', $bookid, PDO::PARAM_INT); |
| 71 | |
| 72 | // Execute the query |
| 73 | $stmt->execute(); |
| 74 | $author_books = []; |
| 75 | |
| 76 | while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { |
| 77 | $author_books[] = $row; |
| 78 | } |
| 79 | }}} |