我想从mysql php检索数据

时间:2018-09-21 06:26:19

标签: php mysql

$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>';
}

我想要所有商品名称,但只打印一个

1 个答案:

答案 0 :(得分:-1)

您无需对记录执行for循环,可以使用while循环获取所有记录,请Plz参考以下代码

$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'];
}