About Me

My photo

I am Ram, a Web Designer and Developer.   More than 4  years of experience in software development. Created complex back-end management systems including content management, e-commerce, customer relations and communication interfaces. The projects based on PHP in conjunction. PHP, SQL, JavaScript, AJAX, XHTML, CSS (Responsive), I help people make beautiful websites, functional applications and seamless user experiences.

Thursday, 12 May 2016

how to calculate running balance like entries of bank passbook using php mysql

how to calculate running balance like entries of bank passbook using php mysql

Demo - Download


Inded.php

<?php
error_reporting(0);
include('connection.php'); ?>
 <div class="col-lg-12">
 <style>
.mytab td, th {
    border: 1px solid #0da3e2;
    padding: 5px !important;
    text-align: center !important;
}

.mytab {
    width: 100%;
}
.red{
    color:red;}
h2{
    text-align:center;
}
</style>
<h2>Libero <span class="red">Ram</span></h2>
<table class="mytab">
<tr style="font-weight:bold">
<td>S.no</td>
<td>date</td>
<td>Credit</td>
<td>Debit</td>
<td>Balance</td></tr>
<?php
$sql = mysql_query("select * from test");
$i =1;
$x =1;

//<!--------- previous_balance using search by date ----->

$cridit =mysql_query("select sum(Credit) AS cri from test where  STR_TO_DATE(TransDate,'%Y-%m-%d')  < '2014-02-21'");
 $cridits= mysql_fetch_assoc($cridit);
 $previous_balance22 = $cridits['cri'] ;

 $Debit =mysql_query("select sum(Debit) AS dit from test where  STR_TO_DATE(TransDate,'%Y-%m-%d')  < '2014-02-21'");
 $Debits= mysql_fetch_assoc($Debit);
   $previous_balance1 = $Debits['dit'] ;
 echo $previous_balance1 =$previous_balance22 -  $previous_balance1;

 //<!--------- previous_balance ----->

while($rlt = mysql_fetch_array($sql)){
$cr = $rlt['Credit'];
$dit= $rlt['Debit'];
$tbal.$i  = ($bal.$i+$cr -$dit - 1);
 ?>

<tr><td><?php echo $x ?></td>
<td><?php echo $rlt['TransDate']; ?></td>
<td><?php echo  $cr ?></td>
<td><?php echo $dit  ?></td>
<td><?php echo $tbal.$i;
?></td>
</tr>
 <?php $i++;  $x++; }

?> </table></div>



Connection.php
<?php
    $dbhost = "localhost";
    $dbusername = "root";
    $dbpassword = "";
    $dbname = "new-trade";
    $item_per_page = 1;
$connection = mysql_connect($dbhost, $dbusername, $dbpassword) or die('Could not connect');
$db = mysql_select_db($dbname);

?>


Demo - Download