php 循环跳过或遗漏了 mysql 查询的一些结果
php loop is skipping or missing some results of mysql query
php 循环跳过或遗漏了 mysql 查询的一些结果,同一个查询在 PhpMyAdmin 中甚至在 sqlYOG 中带来了 181 个结果,因为循环只带来了 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)
php 循环跳过或遗漏了 mysql 查询的一些结果,同一个查询在 PhpMyAdmin 中甚至在 sqlYOG 中带来了 181 个结果,因为循环只带来了 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)