从SQL语句中回显数据

时间:2015-07-21 16:29:22

标签: php mysql

我不是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

1 个答案:

答案 0 :(得分:3)