我有这个功能:
function get_comments($file_id){
echo $file_id.'<br /><br />';
include 'mysql_connect.php'; ($connection is the dblink variable)
$result = mysqli_query($connection, "SELECT * FROM gastenboek");
print $row_cnt = mysqli_num_rows($result);
echo '<br /><br />';
foreach($result as $item){
echo $item['comment'];
}
}
我在 mij db 中创建了 2 条记录,其中包含用于测试的值(也在评论中)。 print $row_cnt 给了我 2 行,但 foreach 语句没有返回任何内容?就像我从语句中得到空行一样?
感谢帮助
最佳答案
执行查询但未获取结果。 将您的代码更新为:
$result = mysqli_query($connection, "SELECT * FROM gastenboek");
print $row_cnt = mysqli_num_rows($result);
echo '<br /><br />';
while($item = mysqli_fetch_assoc($result)){
echo $item['comment'];
}
关于mysql - 我的语句返回空行,即使有带有值的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34897552/