Changes between Version 7 and Version 8 of ImportantCase2


Ignore:
Timestamp:
01/10/25 15:00:18 (5 days ago)
Author:
222039
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ImportantCase2

    v7 v8  
    1414                            WHERE book.genre IN ($placeholders) AND book.PublishedYear BETWEEN $query_from AND $query_to;"
    1515}}}
    16 {{{#!sql
    17 SELECT book.bookid, book.CoverImage, book.Title, book.Genre, book.PublishedYear, author.FirstName, author.LastName
    18                             FROM Book
    19                             INNER JOIN Book_Author ON Book.BookID = Book_Author.BookID
    20                             INNER JOIN Author ON Book_Author.AuthorID = Author.AuthorID WHERE book.PublishedYear BETWEEN $query_from AND $query_to;
    2116
    22 }}}
    2317
    2418
     
    2721[[Image(BT-12.png)]]
    2822{{{#!sql
    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
     41if($year_from === null) {
     42    $query_from = $year_min;
     43}
     44if($year_to === null) {
     45    $query_to = $year_max;
     46}
     47
     48SELECT 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
    3052}}}
    3153