PK

ADDRLIN : C:/Inetpub/vhosts/dharmayatra.co.in/httpdocs/admin/blogs/
FLL :
Current File : C:/Inetpub/vhosts/dharmayatra.co.in/httpdocs/admin/blogs/index.php

<?php
include('../includes/auth.php');
include('../../includes/db.php');
include('../includes/header.php');
include('../includes/sidebar.php');

// Pagination
$limit = 10;
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$offset = ($page - 1) * $limit;

// Fetch blogs
$query = "
SELECT blogs.id, blogs.title, blogs.image, blogs.created_at, blogs.read_time, blog_categories.name AS category
FROM blogs
LEFT JOIN blog_categories ON blogs.category_id = blog_categories.id
ORDER BY blogs.id DESC
LIMIT $limit OFFSET $offset
";

$result = mysqli_query($conn, $query);

// Total count
$totalQuery = mysqli_query($conn, "SELECT COUNT(*) as total FROM blogs");
$totalRow = mysqli_fetch_assoc($totalQuery);
$totalPages = ceil($totalRow['total'] / $limit);
?>

<div class="top-bar">
    <h2>📄 Blogs</h2>
    <a href="./add.php" class="btn btn-primary"><i class="fa fa-plus"></i> Add Blog</a>
</div>

<div class="card">
    <table>
        <tr>
            <th>ID</th>
            <th>Title</th>
            <th>Category</th>
            <th>Read Time</th>
            <th>Action</th>
        </tr>

        <?php while($row = mysqli_fetch_assoc($result)) { ?>
        <tr>
            <td><?= $row['id'] ?></td>
            <td><?= $row['title'] ?></td>
            <td><?= $row['category'] ?? 'N/A' ?></td>
            <td><?= $row['read_time'] ?> min</td>
            <td>
                <a href="edit.php?id=<?= $row['id'] ?>" class="btn btn-warning">Edit</a>
                <a href="delete.php?id=<?= $row['id'] ?>" 
                   class="btn btn-danger"
                   onclick="return confirm('Delete this blog?')">
                   Delete
                </a>
            </td>
        </tr>
        <?php } ?>
    </table>

    <!-- Pagination -->
    <div class="pagination">
        <?php for($i=1; $i<=$totalPages; $i++) { ?>
            <a href="?page=<?= $i ?>" class="<?= ($i == $page) ? 'active' : '' ?>">
                <?= $i ?>
            </a>
        <?php } ?>
    </div>
</div>

<?php include('../includes/footer.php'); ?>


PK 99