PHP CALCULATION FROM MYSQL
require_once('functions.php');
$user = new User;
if (!$user->isLoggedIn) {
die(header("location: login.php"));
}
$cid = $_GET['cid'];
$sql11 = "SELECT * FROM customer where cid = '$cid' ";
$result11 = mysqli_query($connect, $sql11);
$rs = mysqli_fetch_object($result11);
$ob = $rs->cob;
// select customer
$sql0 = "SELECT * FROM customer WHERE cid = '$cid'";
$result0 = mysqli_query($connect, $sql0) or die("Error: " . mysqli_error($connect));
$row0 = mysqli_fetch_array($result0);
//select sales num
$result2 = mysqli_query($connect, "SELECT * FROM tran WHERE cid='$cid' AND ssn != 0") or die("Error: " . mysqli_error($connect));
$row2 = mysqli_fetch_array($result2);
$n = mysqli_num_rows($result2);
//select receipt num
$result3 = mysqli_query($connect, "SELECT * FROM tran WHERE cid='$cid' AND rsn != '0'") or die("Error: " . mysqli_error($connect));
$row3 = mysqli_fetch_array($result3);
$n1 = mysqli_num_rows($result3);
$result4 = mysqli_query($connect, "SELECT sum(samt), sum(ramt) FROM tran WHERE cid='$cid'") or die("Error: " . mysqli_error($connect));
$row4 = mysqli_fetch_array($result4);
$TotalSales = $row4['sum(samt)'];
$TotalReceipt = $row4['sum(ramt)'];
$balance = $ob + $TotalSales - $TotalReceipt;
echo "
";// select tran
$sql = "SELECT * FROM tran WHERE cid = '$cid' ORDER BY date";
$result = mysqli_query($connect, $sql) or die("Error: " . mysqli_error($connect));
while($row = mysqli_fetch_array($result)) {
echo "
if ($row['sref'] > 0) {
echo "" . $row['sref'];
} else {
echo " ";
}
echo "
if ($row['rref'] > 0) {
echo "" . $row['rref'] . "";
} else {
echo " ";
}
echo "
"; if ($row['samt'] > 0) {
echo "
} else {
echo "
}
if ($row['ramt'] > 0) {
echo "
} else {
echo "
}
echo "
"
"; }
echo "
";?>
No comments:
Post a Comment