php循环正在跳过或丢失mysql查询的某些结果,同一个查询在PhpMyAdmin甚至sqlYOG中都会带来181个结果,而as循环只会带来175个结果

$queryos = "SELECT * FROM OSCSBranch AS a
LEFT JOIN
(SELECT ItemCode AS icode FROM NonFood
) AS q ON a.ItemCode = q.icode
WHERE a.BranchId = '$bid' AND a.BType = 'O' AND DATE(a.BDate) = '$date'";

$osquery = mysqli_query($conn, $queryos);
if(!$osquery)
{
die("QUERY FAILED OS " . mysqli_error($conn));
}

while($row = mysqli_fetch_assoc($osquery)){
$total[$row['ItemCode']] = $row['TotalQuantity'];
}

最佳答案

似乎有些记录有相同的'ItemCode'
所以由于$row['ItemCode'] = ....
同样ItemCode的新数据一次又一次地替换旧值,因此您得到的是175条记录,而不是181条
所以你可以这样做:-
或者:-

$total[] = $row['TotalQuantity']; will give you like array(0=>array('name'=>'a',....)....)

或者
$total[$row['ItemCode']][] = $row['TotalQuantity']; //will  give you like array('item201'=>array(0=>array(),1=>array(),...),....) (an example)

10-06 00:25