Jump to content
Sign in to follow this  
prohor

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

Recommended Posts

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!

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
				if($row_inccur['inctype_type']=='Duepay')
				{
					$total_duepay = $total_duepay + $row_inccur['inc_amount']; 
				}
				$remaining_due = $total_row_due - $total_duepay;	
				//echo $remaining_due; 	
					
				}
				
				
				//echo $currentuser; 
					
				echo '<tr>
								<td>
									<a href="customer.php?cust='.$row_custact['cust_id'].'">'.$row_custact['cust_no'].'</a>
								</td>
								<td>'.$row_custact['cust_name'].'</td>
								<td>'.$row_custact['custsex_name'].'</td>
								<td>
								    '.$remaining_due. '  // showing due left, here is the problem 
								</td>
								
								<td>'.$row_custact['cust_address'].'</td>
								<td>'.$row_custact['cust_phone'].'</td>
								<td>'.date("d.m.Y",$row_custact['cust_since']).'</td>
							</tr>';
				}

 

Share this post


Link to post
Share on other sites

You'll have to do some debugging by var_dumping your values at various points and seeing what they are.  Make sure your query is returning the data you think it is.

You should also probably be zeroing out all your variables before the loop so they start fresh for each customer.  Otherwise your previous customer's data will influence the next customers data.

 

 

Share this post


Link to post
Share on other sites
22 hours ago, kicken said:

You'll have to do some debugging by var_dumping your values at various points and seeing what they are.  Make sure your query is returning the data you think it is.

You should also probably be zeroing out all your variables before the loop so they start fresh for each customer.  Otherwise your previous customer's data will influence the next customers data.

 

 

@kicken, Thank you a lot. I will try it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.