mysqli fetch_assoc只有1个结果,而不是全部 [英] mysqli fetch_assoc only 1 result instead of all

查看:74
本文介绍了mysqli fetch_assoc只有1个结果,而不是全部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if ($result = $db->query("SELECT * FROM tab WHERE ID = $id")) {
while($row = $result->fetch_assoc() ){
echo "ID:". $row['ID'];
echo "Product:" .$row['Product'];
... }
$result->close();
} else {
echo "could not retrieve data from db";  }

我只得到一个结果,但是应该更多. 如何获得所有结果?

I only get one result, but it should be a lot more. How do I get all the results?

顺便说一句,我不能使用fetch_all.

btw I cannot use fetch_all.

推荐答案

您在查询中使用的是ID,这意味着您要查询的是特定商品.为了选择所有,您必须删除此条件.

You are using an ID in your query, that means that you are asking for a specific item. In order to select all you have to remove this condition.

您的代码如下:

  if ($result = $db->query("SELECT * FROM tab")) {
    while($row = $result->fetch_assoc() ){
      echo "ID:". $row['ID'];
      echo "Product:" .$row['Product'];
    }
    $result->close();
  } else {
    echo "There is no data in the database";  
  }

这篇关于mysqli fetch_assoc只有1个结果,而不是全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆