如何列出mysqli表中列出的所有相关数据?
问题描述:
如何列出mysqli数据库中的所有相关数据? 我尝试了下面的这些代码。它输出未知的结果:如何列出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 . '';
?>
答
当你调用
echo '' . $id . '';
因为$ ID只存在于范围的foreach $ id不存在了
。
试试这个:
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'] . '';
}
}
?>
@Sébastientemprado不工作,我需要一个更好的结果插入到数据库中 include_once “的init.php”; $ sqli = mysqli_query($ conn,“SELECT * FROM books WHERE book ='1905515'”); $ productCount = mysqli_num_rows($ sqli); 如果($ productCount> 0){ 而 ($ FOW = mysqli_fetch_array($ SQLI)){ 的foreach(如$项FOW $){$ result_from_culumn = $项[ 'ITEM_NAME']; echo''。 $ result_from_culumn。 ''; } } } ?> –
对不起,我不明白。怎么了? –
所有我得到的输出结果是(34526352452552)等等,而我的结果应该是(wap boy fan good),就像插入表格culumn中,您是否看到其他解决方案?谢谢 –