shadowfx88
New Member
I have two tables : \[code\]contract\[/code\] \[code\]bill\[/code\].
\[code\]contract\[/code\] table contains following fields(contId (PK), contractNumber, quantity, etc..).
\[code\]bill\[/code\] contains following fields(billId (PK), billNo, contId, checkMtr, etc...).Here every contract can have multiple bills. What I am trying to do is \[code\]add\[/code\] all the \[code\]inwMtr\[/code\] of a contract and diduct that from the \[code\]quantity\[/code\] and display the final mtrs as Pending Mtr.Here is what I have tried:\[code\]<?phpinclude("dbconnection.php");$sql1 = mysql_query("SELECT quantity FROM contract WHERE contId = '25'");while($result1 = mysql_fetch_array($sql1)){//echo "$result1[quantity]";//echo "<br/>";//echo "<br/>";$sql2 = mysql_query("SELECT checkMtr FROM bill WHERE contId = '25'");while($result2 = mysql_fetch_array($sql2)){//echo "$result2[checkMtr]";//echo "<br/>";$a = $result1['quantity'] - $result2['checkMtr'];echo "$a";echo "<br/>";}echo "<br/>";}echo "<br/>";?>\[/code\]Here it does subtract checkMtr from quantity but it does it for every bill. It doesn't add checkmtrs of all the bills and then subtract.Any suggestions?
\[code\]contract\[/code\] table contains following fields(contId (PK), contractNumber, quantity, etc..).
\[code\]bill\[/code\] contains following fields(billId (PK), billNo, contId, checkMtr, etc...).Here every contract can have multiple bills. What I am trying to do is \[code\]add\[/code\] all the \[code\]inwMtr\[/code\] of a contract and diduct that from the \[code\]quantity\[/code\] and display the final mtrs as Pending Mtr.Here is what I have tried:\[code\]<?phpinclude("dbconnection.php");$sql1 = mysql_query("SELECT quantity FROM contract WHERE contId = '25'");while($result1 = mysql_fetch_array($sql1)){//echo "$result1[quantity]";//echo "<br/>";//echo "<br/>";$sql2 = mysql_query("SELECT checkMtr FROM bill WHERE contId = '25'");while($result2 = mysql_fetch_array($sql2)){//echo "$result2[checkMtr]";//echo "<br/>";$a = $result1['quantity'] - $result2['checkMtr'];echo "$a";echo "<br/>";}echo "<br/>";}echo "<br/>";?>\[/code\]Here it does subtract checkMtr from quantity but it does it for every bill. It doesn't add checkmtrs of all the bills and then subtract.Any suggestions?