Blog Post

Check Out our Articles it may help to start your AI Journey

Mastering the Art of AI Tool: Unleashing the Power of
Automated Creativity with AI Tool Path

0 ? (int)$_GET['page'] : 1; // 计算查询的起始行 $start = ($current_page - 1) * $blogs_per_page; // 使用准备语句查询总的博客数目 $stmt = $conn->prepare("SELECT COUNT(*) as total FROM blogs WHERE status = ?"); $status = 1; $stmt->bind_param("i", $status); $stmt->execute(); $stmt->bind_result($total_blogs); $stmt->fetch(); $stmt->close(); // 计算总页数 $total_pages = ceil($total_blogs / $blogs_per_page); // 获取当前页面的博客数据 $stmt = $conn->prepare("SELECT id, title, image, created_at FROM blogs WHERE status = ? ORDER BY created_at DESC LIMIT ?, ?"); $stmt->bind_param("iii", $status, $start, $blogs_per_page); $stmt->execute(); $result = $stmt->get_result(); // 显示博客 while ($blog = $result->fetch_assoc()) { $id = htmlspecialchars($blog['id']); $title = htmlspecialchars($blog['title']); $image_name = htmlspecialchars($blog['image']); $created_at = new DateTime($blog['created_at']); $formatted_date = $created_at->format('d M Y'); echo " "; } $stmt->close(); ?>
    1) { echo ''; } if ($total_pages <= 6) { // 如果总页数小于或等于6,显示所有页码 for ($page = 1; $page <= $total_pages; $page++) { echo '
  • ' . $page . '
  • '; } } else { // 显示前两页 echo '
  • 1
  • '; echo '
  • 2
  • '; // 如果当前页码大于4,显示省略号 if ($current_page > 4) { echo '
  • ...
  • '; } // 显示中间范围 $start_page = max(3, $current_page - 2); $end_page = min($total_pages - 2, $current_page + 2); for ($page = $start_page; $page <= $end_page; $page++) { echo '
  • ' . $page . '
  • '; } // 如果结束页小于总页数减去2,显示省略号 if ($end_page < $total_pages - 2) { echo '
  • ...
  • '; } // 显示最后两页 echo '
  • ' . ($total_pages - 1) . '
  • '; echo '
  • ' . $total_pages . '
  • '; } // "Next" 按钮 if ($current_page < $total_pages) { echo ''; } ?>