私信  •  关注

phainix

phainix 最近创建的主题
phainix 最近回复了
6 年前
回复了 phainix 创建的主题 » 如何在重新加载页面PHP时检查MySQL表是否为空

选择时 count(*)

$number_of_rows = $result->fetchColumn(); // This contains 1 row, with the column indicating the count and so your condition will never be executed

而是将列命名为 SELECT count(*) as total_posts FROM posts

$row = $stmt->fetch(PDO::FETCH_ASSOC); // Fetch the first row
$total_posts = $row['total_posts']; // Get the column containing the result of the count
// Run your condition $total_posts 

Checkout this answer