当billpay字段没有“付款”值时,我的以下条件无法正常工作。然后,首先“if”现在显示表中102美元的任何数据,它只是显示空白单元格。
if($f1022 ==0){
echo $f102;
}
else {
echo $fpending = $f102 - $f1022;
}
我也尝试过如下,但结果相同,
if(empty($f1022)){
echo $f102;
}
else {
echo $fpending = $f102 - $f1022;
}
和
if($f1022 ==0){
echo $f102;
}
else {
echo $fpending = $f102 - $f1022;
}
下面是带有html表的完整脚本。
<html>
<head>
<style>
table, td, th {
border: 1px solid #ddd;
text-align: left;
}
table {
border-collapse: collapse;
}
th, td {
padding: 15px;
}
</style>
</head>
<body>
<table width="700px" id="workweek" class="wwtable">
<tbody>
<tr>
<th>Supplier</th>
<th>Bill</th>
<th>Payment</th>
<th>Due</th>
</tr>
<?php
error_reporting(1);
$conn = mysqli_connect("127.0.0.1","root","","mehrazin");
$detailss81s = "SELECT *, SUM(acamount) AS sum FROM account WHERE billpay
=
'bill' GROUP BY factsuply ";
$details_results81s = mysqli_query($conn,$detailss81s)
or die ( "Couldn't get Products: ".mysqli_error($conn) );
while ( $det_row = mysqli_fetch_array ( $details_results81s ) )
{//===1st
$f101 = $det_row[ 'factsuply' ];
$f102 = $det_row[ 'sum' ];
?>
<tr>
<td width="400px"><?php echo "$f101"; ?></td>
<td width="100px"><?php echo "$f102"; ?></td>
<?php
$detailss81ss = "SELECT *, SUM(acamount) AS sum FROM account WHERE
factsuply
= '$f101' AND billpay = 'payment' GROUP BY factsuply ";
$details_results81ss = mysqli_query($conn,$detailss81ss)
or die ( "Couldn't get Products: ".mysqli_error($conn) );
while ( $det_rows = mysqli_fetch_array ( $details_results81ss ) )
{//===2nd
$f1022 = $det_rows[ 'sum' ];
?>
<td width="100px"><?php echo "$f1022"; ?></td>
<td width="100px"><?php
if($f1022 ==0){
echo $f102;
}
else {
echo $fpending = $f102 - $f1022;
}
?></td>
<?php
}//===2nd
}//===1st
?>
</tr>
</tbody>
</table>
</body>
</html>
答案 0 :(得分:0)
我认为您的查询是问题的根本原因。就目前而言,ent410373
条款可能完全丢弃某些不匹配的WHERE
组。解决此问题的一种方法是在整个表上使用条件聚合:
factsuply
顺便说一句,与SELECT
factsuply,
SUM(CASE WHEN billpay = 'bill' THEN acamount ELSE 0 END) AS sum
FROM account
GROUP BY factsuply;
一起做SELECT *
通常是件坏事。在您的特定情况下,MySQL容忍它,它甚至似乎不会导致您的问题。但是你应该知道这个查询甚至不会在大多数其他数据库上运行。