当前位置: 首页 > 知识库问答 >
问题:

SQL语法;请检查与您的MariaDB服务器版本相对应的手册,以获得正确的语法

王翰墨
2023-03-14

查询失败您的SQL语法中有一个错误;在第1行“comment_status='approved'ORDER BY comment_id desc”附近,请查看与您的MariaDB服务器版本相对应的手册中使用的正确语法

<?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";

谢谢。

共有1个答案

白越
2023-03-14

尝试包括空格:

$query .= " AND comment_status = 'Approved' ";

注意:如果您想要调试这些类型的问题,那么在运行查询字符串之前输出它。问题往往是显而易见的。

 类似资料: