我有4种付款方式:
现金,信贷,借记卡和薪水。
如果在付款方式中没有商品结果(以前的付款),我正在尝试打印格式<td>0</td>
。我正在寻找的输出示例是:
Credit < td >4000< / td >
Cash < td >0< / td >
Debit < td >2000< / td >
PayCheck < td >0< / td >
这是我的Mysql查询
SELECT SUM(ventas.preciov) as totalp, SUM(boletas.total) as totalb,
boletas.total, boletas.tpago, boletas.idb, boletas.activa, ventas.idbv, ventas.marcap
FROM boletas,ventas
WHERE ventas.idbv = boletas.idb AND ventas.marcap = '1' AND boletas.activa = 's'
AND boletas.fventa >= curdate()-INTERVAL '".$_GET["fventa"]."' day GROUP BY tpago
ORDER BY tpago DESC
这是我的PHP代码
<?php while($result = mysql_fetch_array($query)){
$i=$result["tpago"];
$c= $result["total"];
switch ($i) {
case "Cash":
echo $c;
break;
case "Credit":
echo $c;
break;
case "Debit":
echo $c;
break;
case "Paycheck":
echo $c;
break;
} ?>
感谢您的帮助。
答案 0 :(得分:1)
如果我理解您的问题,那么下面的代码可能对您有所帮助:
<?php
$payment_methods = array('Credit', 'Cash', 'Debit', 'Paycheck');
$total = array();
while($result = mysql_fetch_array($query))
$total[$result['tpago']] = $result['total'];
foreach($payment_methods as $method) {
echo $method.' : '.( empty($total[$method])? 0 : $total[$method] ) . '<br/>';
}
?>