Hi guys, I am building a mini financial Data entry and computation app for my office. Please I have little issue with getting the current balance of account holders, i.e Sum(credit)-Sum(debit) of an account holder. Its displaying the history perfectly, but current balance only gives an error(Warning: mysql_fetch_array() expects parameter 1 to be resource, string given). Kindly help me with this, here’s the code below.
[code]
<table width=”250″ border=”1″ cellspacing=”1″ cellpadding=”1″>
<tr style=”background-color: skyblue” >
<td><a href=”customer.php”> Go Back </a></td><br>
<td><a href=”main_login.php”> Log-Out </a></td>
</tr>
</table>
<table width=”250″ border=”1″ cellspacing=”1″ cellpadding=”1″>
<tr>
<?php
$cname=$_POST[‘cname’];
$cnumber=$_POST[‘cnumber’];
include(‘includes/connection1.php’);
$result1 = “SELECT ((SELECT sum(`cred_amt`) WHERE `accountnumber`= ‘$cnumber’) – (SELECT sum(`deb_amt`) WHERE `accountnumber`= ‘$cnumber’)) AS `tbalance` FROM tbl_totaltransact”;
//$get=mysql_query($result1);
//$get2=mysql_query();
//$get3=[$get-$get2];
while($row = mysql_fetch_array($result1)){
//$row=mysql_fetch_array($result1);
$tbalance=$row[“tbalance”];
?>
<td>Current Balance</td>
<td><?php echo $tbalance ;?></td>
<?php } ?>
</tr>
</table>
<table width=”1000″ border=”1″ cellspacing=”1″ cellpadding=”1″>
<tr> <h2 align=”center”><?php echo $cname.”:”.” “.”History”; ?></h2></tr>
<tr>
<td>Credit Amount</td>
<td>Credit Discription</td>
<td>Date</td>
<td>Debit Amount</td>
<td>Debit Discription</td>
</tr>
<?php
//while($row=mysql_fetch_array($result)){
include(‘includes/connection1.php’);
$result = $db->prepare(“SELECT * FROM tbl_totaltransact WHERE accountname=’$cname’ AND accountnumber=’$cnumber’ ORDER BY date DESC”);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr>
<td><?php echo $row[‘cred_amt’]?></td>
<td><?php echo $row[‘cred_disc’]?></td>
<td><?php echo $row[‘date’]?></td>
<td><?php echo $row[‘deb_amt’]?></td>
<td><?php echo $row[‘deb_disc’]?></td>
<?php } ?>
</tr>
</table>