嗨:)我为自己编写了一些代码,我需要比较不同表中的两列。
我有 table blog_posts
与 postID
我有 table blog_comment
与还有postID
.
我写了这样的开始:
<?php
$stmt2 = $db->prepare('SELECT comment_sender_name, comment_date, comment
FROM blog_posts, blog_comment
WHERE blog_posts.psotID = blog_comment.postID');
$stmt2->execute(array(
':comment_sender_name' => $comment_sender_name,
':comment_date' => $comment_date,
':comment' => $comment
));
if ($row['blog_posts.psotID'] == $row['blog_comment.postID']) {
echo '<p>' . $comment_sender_name . '</p>';
echo '<p>' . $comment_date . '</p>';
echo '<p>' . $comment . '</p>';
} else ($row['blog_posts.psotID'] == '') {
header('Location: ./');
exit;
}
?>
这是我得到的错误:
Parse error: syntax error, unexpected '{' in /home/pomarex1/domains/dev.automax-rent.eu/public_html/comments-loop.php on line 12
最佳答案
我可以在您的代码中看到两个错误(如果这不是拼写错误):-
在您编写“WHERE blog_posts.psotID = blog_comment.postID”的查询中,它应该是“blog_posts.postID”而不是“blog_posts.psotID”,因为 psotID 不是表中的字段。
就像别人说的,你的else是错的,要么你写
其他{ header('位置:./'); 导出; }
或者
else if($row['blog_posts.psotID'] == ''){
header('Location: ./');
exit;
}
- 第三,我建议编写一个内部联接查询,而不是直接调用数据。
关于php - 如何比较不同表中的两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50988368/