我在这里得到了这个PHP代码......
$totalBalance = 0;
foreach($resultArray as $row) {
foreach($row as $key =>$field) {
echo $field['remaining'] . "<br>";
}
}
$resultArray 是从我的 SQL 查询返回到数组中的内容。
余额栏的前几条记录是..
389.96 6433.66 52.52 107.25
但是,当我运行这个 php 代码时,我得到了
1 5 1 3
为什么要这样做,我该如何解决?
如果有帮助,这是 SQL 查询
SELECT c.clientid, c.clientname, c.billingdate,
case when (select ifnull(sum(total), 0) from invoice i
where i.client = c.clientid and i.isdeleted = 0) - (select ifnull(sum(p.amount), 0) from payment p inner join invoice i on p.invoice = i.invoiceid
where i.client = c.clientid and i.isdeleted = 0) < 0 then (select ii.total from invoice ii where ii.client = c.clientid and ii.isdeleted=0 order by ii.invoiceid desc limit 1) else (select ifnull(sum(total), 0) from invoice i
where i.client = c.clientid and i.isdeleted = 0) - (select ifnull(sum(p.amount), 0) from payment p inner join invoice i on p.invoice = i.invoiceid
where i.client = c.clientid and i.isdeleted = 0) end as remaining,
case c.isactive+0
when '1' then 'Stop'
else 'Start'
end as Active
FROM client c
ORDER BY clientname
我做了一个 $resultArray 的 print_r 并得到了这个......
Array ( [0] => Array ( [clientid] => 1 [clientname] => client A [billingdate] => 14 [remaining] => 389.96 [active] => Stop ) [1] => Array ( [clientid] => 178 [clientname] => client B [billingdate] => 23 [remaining] => 6433.66 [active] => Stop ) [2] => Array ( [clientid] => 3 [clientname] => client C [billingdate] => 19 [remaining] => 52.52 [active] => Stop ) [3] => Array ( [clientid] => 105 [clientname] => client D [billingdate] => 23 [remaining] => 107.25 [active] => Start )