D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
proc
/
thread-self
/
root
/
proc
/
self
/
root
/
home
/
markniuj
/
bazmeasar.com
/
Filename :
view_books.php
back
Copy
<?php // Database connection parameters $servername = "localhost"; $username = "markniuj_bazmpbto"; $password = "BC)1at0Y8Wa{"; $dbname = "markniuj_bazmpbto_november-2023"; // Establish a database connection $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $conn->set_charset("utf8mb4"); // Pagination logic $limit = 8; // Number of books per page $page = isset($_GET['page']) ? $_GET['page'] : 1; $start = ($page - 1) * $limit; // Fetch books from the database with pagination $sql = "SELECT title, author, pdf_link, thumbnail, description FROM books ORDER BY id DESC LIMIT $start, $limit"; $result = $conn->query($sql); // Get total number of books for pagination $totalSql = "SELECT COUNT(id) AS total FROM books"; $totalResult = $conn->query($totalSql); $totalBooks = $totalResult->fetch_assoc()['total']; $totalPages = ceil($totalBooks / $limit); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Books Collection</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <style> .header-image { background-image: url('img/books-bg.png'); background-size: cover; height: 300px; position: relative; } .header-text { position: absolute; bottom: 20px; left: 20px; color: white; background-color: rgba(0, 0, 0, 0.6); padding: 10px 20px; border-radius: 5px; } footer { background-color: #f8f9fa; padding: 20px 0; text-align: center; } </style> </head> <body> <!-- Header --> <header class="header-image"> <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"> <a class="navbar-brand" href="#"> <img src="https://bazmeasar.com/img/logo/bazm-e-asar2.png" alt="Logo" width="40" height="40" class="d-inline-block align-top"> Books Collection </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav ms-auto"> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="index.php">Home</a> </li> </ul> </div> </div> </nav> <div class="header-text"> <h1>Welcome to the Books Collection</h1> <p>Explore our vast collection of books and download your favorites.</p> </div> </header> <!-- Main Content --> <div class="container mt-5"> <h2 class="text-center mb-4">Books Collection</h2> <div class="row"> <?php if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $thumbnail = '/' . htmlspecialchars($row['thumbnail']); // Absolute path for thumbnail $pdfLink = htmlspecialchars($row['pdf_link']); $title = htmlspecialchars($row['title']); ?> <div class="col-md-3 mb-3"> <div class="card h-100"> <img src="<?php echo $thumbnail; ?>" class="card-img-top" alt="<?php echo $title; ?>" style="height: auto; object-fit: cover;"> <div class="card-body"> <h5 class="card-title"><?php echo $title; ?></h5> <p class="card-text"><strong>Author:</strong> <?php echo htmlspecialchars($row['author']); ?></p> <p class="card-text"><?php echo htmlspecialchars($row['description']); ?></p> </div> <div class="card-footer text-center"> <a href="<?php echo $pdfLink; ?>" class="btn btn-primary" download="<?php echo $title . '.pdf'; ?>">Download</a> </div> </div> </div> <?php } } else { echo "<p class='text-center'>No books available.</p>"; } ?> </div> <!-- Pagination --> <nav aria-label="Page navigation example"> <ul class="pagination justify-content-center"> <?php if ($page > 1): ?> <li class="page-item"><a class="page-link" href="?page=<?php echo $page - 1; ?>">Previous</a></li> <?php endif; ?> <?php for ($i = 1; $i <= $totalPages; $i++): ?> <li class="page-item <?php if ($i == $page) echo 'active'; ?>"><a class="page-link" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a></li> <?php endfor; ?> <?php if ($page < $totalPages): ?> <li class="page-item"><a class="page-link" href="?page=<?php echo $page + 1; ?>">Next</a></li> <?php endif; ?> </ul> </nav> </div> <!-- Footer --> <footer> <div class="container"> <p>© 2024 Books Collection. All rights reserved.</p> </div> </footer> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html> <?php $conn->close(); ?>