我不是PHP和SQL语句的新手,但我偶然发现了这个问题,并且对如何修复它感到茫然。我的查询没有像我想要的那样显示commentID。
<?php
$query = "SELECT `commentID`, `blogID` FROM blog_comments WHERE blogID = ':postid' ORDER BY commentID DESC LIMIT 1";
$query_params = array(':postid' => $row['postID']);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $e)
{
die($e->getMessage()); // Don't echo $e on prod. site
}
$rows = $stmt->fetchAll();
?>
<?php foreach($rows as $row): ?>
<?php echo $row['commentID']; ?>
<?php endforeach; ?>
comments
答案 0 :(得分:3)
删除WHERE blogID = ':postid'
WHERE blogID = :postid
进行错误检查会发现。
参考文献: