我正在尝试显示我创建的数据库中的所有数据,但是它不会显示所有数据,只显示最近添加的数据。有人能告诉我我的代码有什么问题吗?非常感谢你!
<?php
include 'dbconnect.php';
$query = $db->prepare("SELECT
game_id,
game_name,
history_description,
pl_id
FROM game_post");
$query->execute();
$query->bind_result($game_id, $game_name, $history_description, $pl_id);
?>
<!DOCTYPE html>
<html>
<head>
<title>Trying</title>
</head>
<body>
<?php
while ($query->fetch()); ?>
<article>
<h2><?php echo $game_name; ?></h2>
<p><?php echo $history_description; ?></p>
<p><?php echo $pl_id ; ?></p>
</article>
</body>
</html>
答案 0 :(得分:0)
试试这个,
<?php
$res = $query->fetch();
while($res) {
?>
<article>
<h2><?php echo $row['game_name']; ?></h2>
<p><?php echo $row['history_description']; ?></p>
<p><?php echo $row['pl_id']; ?></p>
<?php } ?>