D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
public_html
/
encoadminders
/
Filename :
blogs.php
back
Copy
<?php // Include the database configuration file require('config.php'); // Delete functionality if (isset($_GET['delete'])) { $id = intval($_GET['delete']); // Fetch the blog to delete its image $query = "SELECT image FROM blogs WHERE id = $id"; $result = $conn->query($query); $row = $result->fetch_assoc(); if ($row) { $imagePath = $row['image']; // Delete the blog from the database $deleteQuery = "DELETE FROM blogs WHERE id = $id"; if ($conn->query($deleteQuery)) { // Delete the image file from the server if (file_exists($imagePath)) { unlink($imagePath); } echo "<script>alert('Blog deleted successfully!'); window.location.href = 'blogs.php';</script>"; } else { echo "<script>alert('Error deleting the blog.');</script>"; } } else { echo "<script>alert('Blog not found.');</script>"; } } ?> <!DOCTYPE html> <html lang="en"> <head> <?php include('style.php') ?> <title>All Blogs</title> <style> /* Base Styling */ body { font-family: 'Poppins', sans-serif; background-color: #f8f9fa; margin: 0; padding: 0; } h2 { text-align: center; margin: 20px 0; color: #333; } .container { max-width: 1200px; margin: 0 auto; padding: 20px; background: #fff; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } .btn { padding: 10px 20px; font-size: 14px; border: none; border-radius: 5px; text-decoration: none; color: #fff; transition: all 0.3s ease-in-out; } .btn-success { background-color: #28a745; } .btn-success:hover { background-color: #218838; } .btn-warning { background-color: #ffc107; color: #333; } .btn-warning:hover { background-color: #e0a800; } .btn-danger { background-color: #dc3545; } .btn-danger:hover { background-color: #c82333; } table { width: 100%; border-collapse: collapse; margin-top: 20px; } table th, table td { text-align: left; padding: 12px 15px; border: 1px solid #ddd; } table th { background-color: #f2f2f2; font-weight: bold; } table td img { max-width: 100px; border-radius: 5px; } @media (max-width: 768px) { .container { padding: 15px; } table { font-size: 14px; } table th, table td { padding: 8px 10px; } .btn { font-size: 12px; padding: 8px 15px; } } @media (max-width: 480px) { table, table thead, table tbody, table th, table td, table tr { display: block; width: 100%; } table tr { margin-bottom: 15px; border-bottom: 1px solid #ddd; padding-bottom: 10px; } table th { display: none; } table td { text-align: right; padding-left: 50%; position: relative; } table td::before { content: attr(data-label); position: absolute; left: 10px; font-weight: bold; color: #666; text-align: left; } .btn { display: block; width: 100%; margin-bottom: 10px; font-size: 14px; } } </style> </head> <body> <?php include('sidebar.php') ?> <div class="home-section"> <div class="container"> <h2>All Blogs</h2> <!-- Add New Blog Button --> <a href="add_blog.php" class="btn btn-success">Add New Blog</a> <!-- Display Blogs Here --> <table class="table"> <thead> <tr> <th>Title</th> <th>Short Description</th> <th>Content</th> <th>Image</th> <th>Action</th> </tr> </thead> <tbody> <?php $query = "SELECT * FROM blogs"; $result = $conn->query($query); while ($row = $result->fetch_assoc()) { $content = strip_tags(html_entity_decode($row['content'])); $short_content = strlen($content) > 50 ? substr($content, 0, 50) . '...' : $content; $short_desc = htmlspecialchars($row['short_desc']); // Fetching short description echo "<tr> <td data-label='Title'>" . htmlspecialchars($row['title']) . "</td> <td data-label='Short Description'>" . $short_desc . "</td> <td data-label='Content'>" . htmlspecialchars($short_content) . "</td> <td data-label='Image'><img src='{$row['image']}' alt='Blog Image'></td> <td data-label='Action'> <a href='edit_blog.php?id={$row['id']}' class='btn btn-warning'>Edit</a> <a href='blogs.php?delete={$row['id']}' class='btn btn-danger' onclick=\"return confirm('Are you sure?');\">Delete</a> </td> </tr>"; } ?> </tbody> </table> </div> </div> <?php include('footer.php') ?> </body> </html>