【发布时间】:2014-11-29 13:54:26
【问题描述】:
我正在尝试使用 MySQl 准备好的语句从数据库中获取行并获取结果。但是,这是行不通的。
请有人看看我哪里出错了?我已经尝试了几个小时的解决方案,但我无法让它发挥作用。页面只是没有加载,好像查询失败了。
$tag = trim($_GET['tag']);
$stmt = $mysqli->prepare('SELECT posts.* FROM tags JOIN posts ON posts.id = tags.post_id WHERE tag = ?');
$stmt->bind_param('s', $tag);
$stmt->execute();
$stmt->store_result();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo $row['tag'];
}
$stmt->free_result();
$stmt->close();
【问题讨论】:
-
您是否检查过您的查询是否有结果?
-
是的,它返回 4 行
标签: php mysql loops while-loop