<?php

require __DIR__ . "/../db/database.php";

if(isset($_GET['letter'])) {
    $letter = $_GET['letter'];
    $sql = "SELECT * FROM books WHERE title LIKE '$letter%'";
} else {
    $sql = "SELECT * FROM books";
}

$all_books = $mysqli->query($sql);

while($row = mysqli_fetch_assoc($all_books)) {
    echo '<div class="card">';
    echo '<div class="image">';
    echo '<img src="../uploads/' . $row["image"] . '" alt="">';
    echo '</div>';
    echo '<div class="info">';
    echo '<h2 class="heading" title="' . $row["title"] . '">' . (mb_strlen($row["title"]) > 15 ? mb_substr($row["title"], 0, 8) . '...' : $row["title"]) . '</h2>';
    echo '<p class="description">' . $row["description"] . '</p>';
    echo '</div>';
    echo '</div>';
}