wiki:ImportantCase3

Version 10 (modified by 222039, 4 days ago) ( diff )

--

Детален приказ на книга

Актери

  • Најавен корисник

Чекор 1

Корисникот ја избира книгата за која сака да види подетални информации

Чекор 2

Детален приказ на книгата

 $sql = "SELECT book.*, book_details.*, firstname, lastname, author_description, author_image FROM book
            INNER JOIN book_author ON book.bookid =  book_author.bookid
            INNER JOIN author ON book_author.authorid = author.authorid
            INNER JOIN book_details ON book.bookid = book_details.bookid
            WHERE book.bookid = :bookid;
            ";
    $stmt = $conn->prepare($sql);
    $stmt->bindParam(':bookid', $param, PDO::PARAM_INT);

    $sql2 = "SELECT 
                b.BookID, 
                b.TotalCopies - COALESCE(COUNT(l.LoanID), 0) AS AvailableCopies
                FROM Book b
                LEFT JOIN Loan l 
                ON l.BookCopyID IN (SELECT CopyID FROM Book_Copies WHERE BookID = b.BookID)
                AND l.Status IN ('On Time', 'Soon', 'Overdue')
                WHERE 
                    b.BookID = :bookid
                GROUP BY 
                    b.BookID, b.TotalCopies;";

Чекор 3

Повеќе книги

//Similar Books
    $stmt = $conn->prepare("SELECT book.bookid, coverimage, title, genre, firstname, lastname FROM book
        INNER JOIN book_author ON book.bookid =  book_author.bookid
        INNER JOIN author ON book_author.authorid = author.authorid
        WHERE book.genre = :bookgenre AND book.bookid != :bookid LIMIT 5;
    ");
    $stmt->bindParam(':bookgenre', $book_genre, PDO::PARAM_STR);
    $stmt->bindParam(':bookid', $bookid, PDO::PARAM_INT);
    // Execute the query
    $stmt->execute();
    $similar_books = [];

    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
      $similar_books[] = $row;
    }

    //More Author
    $stmt = $conn->prepare("SELECT book.bookid, coverimage, title, genre, firstname, lastname 
    FROM book
    INNER JOIN book_author ON book.bookid = book_author.bookid
    INNER JOIN author ON book_author.authorid = author.authorid
    WHERE book_author.authorid IN (
        SELECT book_author.authorid 
        FROM book_author 
        WHERE book_author.bookid = :bookid
    ) AND book.bookid != :bookid
    LIMIT 5;
    ");
    $stmt->bindParam(':bookid', $bookid, PDO::PARAM_INT);

    // Execute the query
    $stmt->execute();
    $author_books = [];

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $author_books[] = $row;
    }

Attachments (3)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.