I have a MySQL table payment where I store all the payment related data of my client. The table fields are: fileNo, clientName, billNo, billAmount, status. I want to build a search form where I will input the fileNo or the clientName, which will yield a table fetching all the records for that file number or the client name where status = 0 (unpaid). Here billAmount is a floating point number.
I am no good in MySQL, but here is my version of the SQL by fileNo
$sql = "SELECT * FROM `payment` WHERE `fileNo` = '$fileNo' AND `status` = '0'";
SQL by clientName
$sql = "SELECT * FROM `payment` WHERE `clientName` = '$clientName' AND `status` = '0'";
either way I make the query, I will also need to show the total unpaid amount against that fileNo or clientName.
From my understanding, the SUM() operation should be something like this:
$sql = "SELECT SUM(billAmount) AS `unpaid` WHERE `fileNo` = '$fileNo' AND `status` = '0'";
or
$sql = "SELECT SUM(billAmount) AS `unpaid` WHERE `clientName` = '$clientName' AND `status` = '0'";
My question is, am I correct with my SUM() operation? And how do I get the total unpaid amount that I selected as unpaid? can I store it in a variable?
Any idea, suggestions or resource link will be much appreciated!
i think u should use the second query but u missed WHEre clause
your total amount unpaid yes u cant get it as variable like that
of course after u fetch your query .