【发布时间】:2016-06-17 17:20:14
【问题描述】:
查询失败您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的 'comment_status = 'Approved' ORDER BY comment_id DESC' 附近使用正确的语法
这是我的代码
<?php
$query = "SELECT * FROM comments WHERE comment_post_id = {$the_post_id}";
$query .= "AND comment_status = 'Approved' ";
$query .= "ORDER BY comment_id DESC";
$select_comment_query = mysqli_query($connection, $query);
if(!$select_comment_query){
die('Query Failed'. mysqli_error($connection));
}
while ($row = mysqli_fetch_array($select_comment_query)) {
$comment_date = $row['comment_date'];
$comment_content = $row['comment_content'];
$comment_author = $row['comment_author'];
?>
<!-- Comments -->
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="http://placehold.it/64x64" alt="">
</a>
<div class="media-body">
<h4 class="media-heading"><?php echo $comment_author; ?>
<small><?php echo $comment_date; ?></small>
</h4>
<?php echo $comment_content; ?>
</div>
</div>
<?php } ?>
如果我禁用以下代码,它会起作用
$query .= "AND comment_status = 'Approved' ";
$query .= "ORDER BY comment_id DESC";
谢谢
【问题讨论】:
-
我在第二行的
{$the_post_id}之后或AND之前再精简一个空间。 -
就在您致电
mysqli_query()、echo之前,请查看$query的内容,看看您是否通过了您认为自己通过的查询。 -
先给某人标记然后再标记另一个人是不好的。
-
而且我认为我的回答更具描述性,并且有更好的建议。无意冒犯,我删除了我的答案