29 | | SELECT MIN(PublishedYear) as min_year, MAX(PublishedYear) as max_year FROM Book |
| 23 | $year_query = "SELECT MIN(PublishedYear) as min_year, MAX(PublishedYear) as max_year FROM Book"; |
| 24 | $year_stmt = $conn->prepare($year_query); |
| 25 | $year_stmt->execute(); |
| 26 | $year_range = $year_stmt->fetch(PDO::FETCH_ASSOC); |
| 27 | |
| 28 | |
| 29 | $where_conditions = []; |
| 30 | $params = []; |
| 31 | |
| 32 | $year_from = isset($_GET['year_from']) ? (int)$_GET['year_from'] : null; |
| 33 | $year_to = isset($_GET['year_to']) ? (int)$_GET['year_to'] : null; |
| 34 | |
| 35 | $year_min = $year_range['min_year']; |
| 36 | $year_max = $year_range['max_year']; |
| 37 | |
| 38 | $query_from = $year_from; |
| 39 | $query_to = $year_to; |
| 40 | |
| 41 | if($year_from === null) { |
| 42 | $query_from = $year_min; |
| 43 | } |
| 44 | if($year_to === null) { |
| 45 | $query_to = $year_max; |
| 46 | } |
| 47 | |
| 48 | SELECT book.bookid, book.CoverImage, book.Title, book.Genre, book.PublishedYear, author.FirstName, author.LastName |
| 49 | FROM Book |
| 50 | INNER JOIN Book_Author ON Book.BookID = Book_Author.BookID |
| 51 | INNER JOIN Author ON Book_Author.AuthorID = Author.AuthorID WHERE book.PublishedYear BETWEEN $query_from AND $query_to |