prohor Posted July 18, 2020 Share Posted July 18, 2020 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>'; } Quote Link to comment Share on other sites More sharing options...
kicken Posted July 18, 2020 Share Posted July 18, 2020 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. Quote Link to comment Share on other sites More sharing options...
prohor Posted July 19, 2020 Author Share Posted July 19, 2020 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.