0
我對PHP和SQL語句並不陌生,但是我偶然發現了這個問題,並且對如何解決這個問題感到不知所措。我的查詢不像我想要的那樣顯示commentID。從SQL語句中回傳數據
<?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