Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php fetch_assoc仅为多个相同行显示一行_Php_Mysql_Mysqli_Fetch - Fatal编程技术网

php fetch_assoc仅为多个相同行显示一行

php fetch_assoc仅为多个相同行显示一行,php,mysql,mysqli,fetch,Php,Mysql,Mysqli,Fetch,我希望下面代码的查询结果包含两行值完全相同的行,但这两行只显示一行,其他行显示正确,当我在数据库中运行查询时,查询工作正常。我找到的解决方案是在select查询中添加唯一id,但我想知道为什么php跳过一行 $queryitem=$newconn->query("select productname, qty from table where condition"); $result=array(); $count=0; while ($item=$queryitem->fe

我希望下面代码的查询结果包含两行值完全相同的行,但这两行只显示一行,其他行显示正确,当我在数据库中运行查询时,查询工作正常。我找到的解决方案是在select查询中添加唯一id,但我想知道为什么php跳过一行

 $queryitem=$newconn->query("select productname, qty from table where condition");
 $result=array();
 $count=0;
 while ($item=$queryitem->fetch_assoc()){
    $result[$count]=$item;
    $count+=1;
 }
预期结果(查询结果以db显示):

受精结果:

          productname    qty
          aaa             10
          bbb              5

$count
不需要,
$result[]=$item请打印($result)
。另外,您是否有可能使用($i=1;…)?我以前打印过($result),它显示获取跳过的第二个aaa记录,for循环对我的情况不好,顺便说一句,我当前的解决方案是在select查询中包含id,因此记录变得不同,但我想知道原因,以及是否有其他方法不需要
$count
$result[]=$item请打印($result)
。另外,您是否有可能使用($i=1;…)?我以前打印过($result),它显示获取跳过的第二个aaa记录,for循环对我的情况不好,顺便说一下,我当前的解决方案是在select查询中包含id,因此记录变得不同,但我想知道原因以及是否有其他方法
          productname    qty
          aaa             10
          bbb              5