Server : Apache System : Linux server1.cgrithy.com 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64 User : nobody ( 99) PHP Version : 8.1.23 Disable Function : NONE Directory : /home/dnlcambodia/www/dnl_dashboard/PHP/ |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Posts</title> <link rel="stylesheet" type="text/css" href="../Css/posts.css"> <!-- Assuming you have a separate CSS file named style.css for styling --> <style> .edit, .delete { display: flex; padding: 5px 10px; font-size: 12px; /* Adjust the font size as needed */ text-decoration: none; background-color: #007bff; color: white; border: none; border-radius: 3px; cursor: pointer; margin-right: 5px; } .edit:hover, .delete:hover { background-color: #0056b3; } </style> </head> <body> <?php include './config/db_conn.php'; // Add a button to create a new post // Query to retrieve posts from the database $sql = "SELECT id, title, content, date, posted_by, tag, image FROM posts"; $result = $conn->query($sql); // Check if there are rows in the result if ($result->num_rows > 0) { echo "<table border='1'>"; echo "<tr><th>Title</th><th>Content</th><th>Date</th><th>Posted By</th><th>Tag</th><th>Image</th><th>Action</th></tr>"; // Output data of each row while ($row = $result->fetch_assoc()) { echo "<tr>"; // Display only the first 50 characters of the title $title = substr($row["title"], 0, 20); // Display only the first 50 characters of the title echo "<td>" . (strlen($row["title"]) > 20 ? $title . "..." : $title) . "</td>"; // Display only the first 120 characters of the content $content = substr($row["content"], 0, 120); // Append "..." if the content exceeds 120 characters echo "<td>" . (strlen($row["content"]) > 120 ? $content . "..." : $content) . "</td>"; echo "<td>" . $row["date"] . "</td>"; echo "<td>" . $row["posted_by"] . "</td>"; echo "<td>" . $row["tag"] . "</td>"; echo "<td><img src='." . $row["image"] . "' alt='Image' style='max-width: 50px; max-height: 50px;'></td>"; echo "<td><a class='edit' href='updateBlogPost.php?id=" . $row["id"] . "'>Edit</a><a class='delete' href='delete.php?id=" . $row["id"] . "' onclick='return confirm(\"Are you sure?\");'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; } else { echo "<p>No posts found.</p>"; } // Close the database connection $conn->close(); ?> </body> </html>