SQL查询不返回数组

时间:2017-05-17 21:39:14

标签: php mysqli

使用一个页面构建一个从数据库返回的数组来发布一个故事,不知道它不起作用。页面网址如下所示:https://ohcrap.ninja/games/ps4/article.php?id=1

以下是应该生成内容的代码:

        <?php

        $id = $_GET['id'];
        $query = mysqli_query($con,'SELECT * FROM `PS4` WHERE `id` =' .$id) or die(mysqli_error($con));
        while ($row = mysqli_fetch_array($query));
        // Echo page content
                echo "<div class='col s12 m12 l12'>";
                echo "<div class='card small grey darken-3'>";
                echo "<div class='card-stacked'>";
                echo "<div class='card-content'>";
                echo "$id";
                echo "<span class='card-title'>" . $row['title'] . "</span>";
                echo "<hr color='black'>";
                echo "<P>By:<i> " . $row['author'] . "</i></P>";
                echo "<P>Published: " . $row['published'] . "</P>"; 
                echo "<br>";
                echo "<P class='truncate'>" . $row['story'] . "</P>";
                echo "</div>";
                echo "</div>";
                echo "</div>";
                echo "</div>";
    ?>

1 个答案:

答案 0 :(得分:1)

您的while循环没有做任何有用的事情,因为您立即以;结束它。

while ($row = mysqli_fetch_array($query)) {
    // all those echoes
}