我想从mysql php中检索数据

vc6uscn9  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(351)
$query_importer1 = "SELECT * FROM items where item_id ='".$row1["item_id"]."'limit 5 ";

$result_importer1 = mysqli_query($conn,$query_importer1);

for ($i=0; $i<=mysqli_num_rows($result_importer1); $i++)

{ 
    $row = mysqli_fetch_assoc($result_importer1);
    echo ''.$row['item_name'].'<br>';
}

我想要所有的项目名称,但它只打印一个

avwztpqn

avwztpqn1#

您不需要对记录执行for循环,您可以使用while循环获取所有记录,请参阅下面的代码

$query_importer1 = "SELECT * FROM items where item_id ='".$row1["item_id"]."' limit 5 ";

$result_importer1 = mysqli_query($conn,$query_importer1);

while($row = mysqli_fetch_assoc($result_importer1)){
    echo $row['item_name'];
}

相关问题