having an issue with viewing numeric data, mainly deposit, withdraw and balance, with balance calculated from deposit & withdraw filed.
Data is shown correctly along with balances but with large amount of data the display needs to be scrolled.
What is required is that it is shown page wise (say 20 lines or so), along with NEXT & PREVIOUS buttons. This is also working, but the problem is with the balances, when you press the NEXT button, the last balance is not taken into consideration but the fresh one is, needless to say the balances are all wrong.
All the current data should be on top and not at the bottom.!
<?php
session_start();
setlocale(LC_MONETARY, 'en_IN');
date_default_timezone_set('Asia/Kolkata');
include "config.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="container">
<div class="parent">
<?php include "head.php"; ?>
<aside class="section leftSidebar">
<?php include "left.php"; ?>
</aside>
<main class="section main">
<table class="tg">
<colgroup>
<col style="width: 90px" />
<col style="width: 200px" />
<col style="width: 100px" />
<col style="width: 100px" />
<col style="width: 120px" />
<col style="width: 90px" />
</colgroup>
<thead>
</thead>
<tbody>
<tr>
<td class="tg-h2xt">Date</td>
<td class="tg-h2xt">Particulars</td>
<td class="tg-h2xt">Deposit</td>
<td class="tg-h2xt">Withdraw</td>
<td class="tg-h2xt">Balance</td>
<td class="tg-h2xt">Action</td>
</tr>
<tr>
<?php
if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
$startrow = 0;
} else {
$startrow = (int)$_GET['startrow'];
}
$sql = "SELECT * FROM sundry ORDER BY sdate ASC LIMIT $startrow,22";
$result_data=mysqli_query($conn, $sql);
while ($row_data = mysqli_fetch_assoc($result_data)) {
$start_line = $start_line+1;
$date=$row_data['sdate'];
$date=strtotime($date);
$sdate=date('d-m-yy',$date);
$spart=$row_data['spart'];
$deposit=$row_data["sdeposit"];
$withdraw=$row_data["swithdraw"];
$dep_sum +=$deposit;
$wit_sum +=$withdraw;
$total=$balance+$dep_sum-$wit_sum;
echo "<tr>";
echo "<td class='tg-0pky'>" ."$sdate". "</td>";
echo "<td class='tg-0pky'>" .$row_data["spart"]. "</td>";
echo "<td class='tg-dvpl'>" .number_format($deposit,2). "</td>";
echo "<td class='tg-dvpl'>" .number_format($withdraw,2). "</td>";
echo "<td class='tg-dvpl'>" .money_format('%!i',$total). "</td>";
echo "<td class='tg-dvpl'><form class='new' action= '' method='POST'><input type='hidden' name='id' value=" .$row_data['sid']. "><input type='submit' class='cancelbtn1' name='delete' value='DELETE''></form></td>";
if(isset($_POST['id'])) {
$id=$_REQUEST['id'];
$query = "DELETE FROM sundry WHERE sid=$id ";
$result = mysqli_query($conn,$query);
header("Location: sundry.php");
}
}
echo "<div>";
echo "SUNDRY EXPENSES";
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+22).'"><button style=margin-left:34.0em;width:10%; >Next</button></a>';
$prev = $startrow - 22;
echo "</table>";
if ($prev >= 0) {
echo "<div style=width:10%; >";
echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'"><button style=margin-left:46.0em; >Previous</button</a>';
$balance=$total;
}
?>
</div>
</main>
</div>
<aside class="section rightSidebar">
<table class="tg">
</tbody>
</table>
</aside>
<footer class="section footer ">
<form name="sundry" action="sinsert.php" method="POST">
Transaction Date:
<input type="date" name="s_date" required=" " />
Particulars:
<input type="text" name="s_part" required=" " />
Transaction Amount:
<input type="number" placeholder="00.00" name="s_amount" required=" " />
<input class= 'blue' type=submit name="deposit" value="Deposit" />
<input class = 'red' type=submit name="withdraw" value="Withdraw" />
<input class = 'green'type=reset name="Reset" value="Reset"/>
</form>
</footer>
</div>
</div>
</body>
<?php
?>
</html>