我不知道如何将我的数据库交易数据显示为自动金额,如会计系统。
我需要显示应收金额,收款金额和到期金额的数据,如下例所示:http://i.stack.imgur.com/JSFW8.jpg
<?php $sqlnew="SELECT tranjection.id, tranjection.date, project.project_name,project.amount,tranjection.receive_ammount FROM project JOIN tranjection on project.project_name=tranjection.project_name where project.project_name='dp' " ; $resultnew=mysql_query($sqlnew);
$sl="1" ; ?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td align="center"><strong>Sl</strong>
</td>
<td align="center"><strong>Tran id</strong>
</td>
<td align="center"><strong>Tran date</strong>
</td>
<td align="center"><strong>Project Name</strong>
</td>
<td align="center"><strong>Receivable Amount</strong>
</td>
<td align="center"><strong>Receive Amount</strong>
</td>
<td align="center"><strong>Due</strong>
</td>
</tr>
<?php while($rows=mysql_fetch_array($resultnew)){ ?>
<tr>
<td>
<?php echo $sl++; ?>
</td>
<td>
<?php echo $rows[ 'id']; ?>
</td>
<td>
<?php echo $rows[ 'date']; ?>
</td>
<td>
<?php echo $rows[ 'project_name']; ?>
</td>
<td>
<?php echo $rows[ 'amount']; ; ?>
</td>
<td>
<?php echo $rec1=$receive_ammount=$rows[ 'receive_ammount']; ?>
</td>
<td>
<?php echo $rec1 ; ?>
</td>
</tr>
<?php } ?>
</table>
</td>
</tr>
</table>
答案 0 :(得分:0)
你应该表明你得到了什么作为输出/或是否有任何错误。
根据我的理解,最后的PHP代码应如下所示:
<?php while($rows=mysql_fetch_array($resultnew)){
if(!isset($rec1)) $rec1=$rows["amount"];
//as we only want to set this in first loop. don't create $rec1 before while, if you created any then use another variable here. $rec1 should be unset. ?>
<tr>
<td><?php echo $sl++; ?></td>
<td><?php echo $rows[ 'id']; ?></td>
<td><?php echo $rows[ 'date']; ?></td>
<td><?php echo $rows[ 'project_name']; ?></td>
<td><?php echo $rec1; ?></td>
<td><?php
echo $receive_ammount=$rows[ 'receive_ammount'];
$rec1-=$receive_amount; ?>
</td>
<td><?php echo $rec1 ; ?></td>
</tr>
<?php } ?>