如何一个接一个地列出mysqli数据库中的所有相关数据? 我在下面尝试了这些代码。它输出未知结果:
<?php
include_once "init.php";
$sqli = mysqli_query($conn, "SELECT * FROM books WHERE book='1905515'");
$productCount = mysqli_num_rows($sqli);
if ($productCount > 0) {
while($fow = mysqli_fetch_array($sqli)){
foreach ($fow as $item) {
$id = $item['item_name'];
}
}
}
echo '' . $id . '';
?>
答案 0 :(得分:0)
当你致电echo '' . $id . '';
时,$ id不再存在,因为$ id仅存在于foreach范围内。
试试这个:
include_once "init.php";
$sqli = mysqli_query($conn, "SELECT * FROM books WHERE book='1905515'");
$productCount = mysqli_num_rows($sqli);
if ($productCount > 0) {
while($fow = mysqli_fetch_array($sqli)){
echo '' . $fow['item_name'] . '';
}
}
?>