Why in 'due column', same value is showing for every clients?

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 16
Joined: Sun Sep 11, 2016 8:38 am

Fri Jul 17, 2020 9:56 pm

I have become able to display due data in due column but the same value is showing for each customer - what is the wrong I am doing? Here is the code, please somebody help!

Code: Select all

while ($row_custact = mysqli_fetch_assoc($query_custact)){
				$currentuser = $row_custact['cust_id']; 
				$sql_inccur ="SELECT i.inc_date, t.inctype_type, i.inc_amount, i.inc_text, c.cust_no, c.cust_name, i.inc_receipt
                From customer AS c
                LEFT JOIN incomes AS i ON c.cust_id = i.cust_id 
                LEFT JOIN inctype AS t ON i.inctype_id = t.inctype_id
                WHERE c.cust_id = '$currentuser'
                ORDER BY inc_date DESC";

                $query_inccur = mysqli_query($db_link, $sql_inccur);
	            checkSQL($db_link, $query_inccur);      
				while ($row_inccur = mysqli_fetch_assoc($query_inccur)){
				$inc_amount = $row_inccur['inc_amount'];
				$inc_text = $row_inccur['inc_text'];	
				//Iterate over income types and add matching incomes to $total
						$total_row = $total_row + $row_inccur['inc_amount'];  
						$total_paid = $total_paid + $total_row;
				// part for total due finding.. and "inc_text" is due column
				        $total_row_due = $total_row_due + $row_inccur['inc_text'];  
				        $total_due = $total_due + $total_row_due;
				// this part gathers only total due paied for an account
					$total_duepay = $total_duepay + $row_inccur['inc_amount']; 
				$remaining_due = $total_row_due - $total_duepay;	
				//echo $remaining_due; 	
				//echo $currentuser; 
				echo '<tr>
									<a href="customer.php?cust='.$row_custact['cust_id'].'">'.$row_custact['cust_no'].'</a>
								    '.$remaining_due. '  // showing due left, here is the problem 
User avatar
php-forum GURU
php-forum GURU
Posts: 1186
Joined: Mon Feb 22, 2016 5:52 pm

Sat Jul 18, 2020 5:15 am

Use MySQLi to do all of that for you using aggregate functions, it will sum all the values saving all of those while loops.
Post Reply