scc24php/adminidwnew9uhwef8f/page-list.php

120 lines
4.1 KiB
PHP

<?php
require('../.hta_config/env.php');
require('../.hta_header.php');
require('../.hta_admin_header.php');
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Define the number of results per page
$results_per_page = 30;
// Get the current page number from the URL (default to page 1)
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1;
$offset = ($page - 1) * $results_per_page;
// Get total number of records
$total_stmt = $conn->prepare("SELECT COUNT(*) AS total FROM `scc24`");
$total_stmt->execute();
$total_rows = $total_stmt->fetch(PDO::FETCH_ASSOC)['total'];
$total_pages = ceil($total_rows / $results_per_page);
// Fetch paginated records
$stmt = $conn->prepare("SELECT * FROM `scc24` ORDER BY id DESC LIMIT :limit OFFSET :offset");
$stmt->bindValue(':limit', $results_per_page, PDO::PARAM_INT);
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();
$content = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<p style="font-size: 25px; text-align: center; margin-top: 10px;">Page Content List</p>
<div class="table-container">
<table class="responsive-table">
<thead>
<tr>
<th style="border: 2px solid #7a7a7a;">ID</th>
<th style="border: 2px solid #7a7a7a;">Type</th>
<th style="border: 2px solid #7a7a7a;">Title</th>
<th style="border: 2px solid #7a7a7a;">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($content as $pageData) { ?>
<tr>
<td style="border: 2px solid #7a7a7a;"><?php echo $pageData['id']; ?></td>
<td style="border: 2px solid #7a7a7a;"><?php echo $pageData['type']; ?></td>
<td style="border: 2px solid #7a7a7a;"><?php echo $pageData['title']; ?></td>
<td style="border: 2px solid #7a7a7a;">
<div style="display: flex; flex-direction: row; justify-content: center; color: blue;">
<a href="edit-content.php?id=<?php echo $pageData['id'] . '&slug=' . $pageData['slug'] . '&type=' . $pageData['type']; ?>">Edit</a> &nbsp;
<a target="_blank" href="<?php
if ($pageData['type'] === 'notice') {
echo '/notice/' . $pageData['slug'] . '.html';
} elseif ($pageData['type'] === 'page') {
echo '/' . $pageData['slug'] . '.html';
}
?>">View</a>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- Pagination Links -->
<div style="text-align: center; margin-top: 20px; display: flex; flex-direction: row; gap: 20px; justify-content: center;">
<?php if ($page > 1): ?>
<a href="?page=1">First</a>
<a href="?page=<?php echo $page - 1; ?>">Prev</a>
<?php endif; ?>
<span>Page <?php echo $page; ?> of <?php echo $total_pages; ?></span>
<?php if ($page < $total_pages): ?>
<a href="?page=<?php echo $page + 1; ?>">Next</a>
<a href="?page=<?php echo $total_pages; ?>">Last</a>
<?php endif; ?>
</div>
<?php require('../.hta_footer.php'); ?>
<style>
.table-container {
margin: 20px auto;
width: 90%;
max-width: 900px;
}
.table-container {
overflow-x: auto;
/* margin-top: 20px; */
}
.responsive-table {
width: 100%;
border-collapse: collapse;
margin: 0 auto;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
}
.responsive-table th, .responsive-table td {
border: 2px solid #7a7a7a;
padding: 10px;
/* text-align: center; */
}
.responsive-table th {
background-color: #402517;
color: #fff;
}
@media (max-width: 600px) {
.responsive-table {
font-size: 14px;
}
.action-btn {
font-size: 12px;
padding: 6px 8px;
}
}
</style>