DrTrans Posted May 27, 2012 Share Posted May 27, 2012 What I'm trying to do is basically keep a record of numbers with a balance kinda like a check ledger. current code $query = "SELECT * FROM payments WHERE propid = '$propid' ORDER BY pay_date DESC "; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $pay_id = $row['id']; $pay_message = $row['pay_message']; $pay_smessage = substr($pay_message,0, 15); $pay_who = $row['pay_who']; $pay_date = $row['pay_date']; $pay_amount = $row['pay_amount']; $pay_controller = $row['pay_controller']; if($pay_controller == "-") { $fontcolor = "red"; } if($pay_controller == "+") { $fontcolor = "black"; } print"<tr onMouseOver=\"this.bgColor = '#CEE3F6'\" onMouseOut =\"this.bgColor = '#FFFFFF'\"> <td onclick=\"window.alert('Username: $pay_who Message: $pay_message')\">$pay_id</td><td>$pay_who</td><td>$pay_date</td><td><font color=\"$fontcolor\">$$pay_amount</font></td><td>$$balance</td> "; I know its dirty.. I can make it show the results from the db, and mark them as Red and Black. now i need it to add and subtract them based on the pay_controller . Can someone please help. Quote Link to comment https://forums.phpfreaks.com/topic/263230-simple-calculations/ Share on other sites More sharing options...
Barand Posted May 27, 2012 Share Posted May 27, 2012 SELECT pay_controller, SUM(pay_amount) as total FROM payments GROUP BY pay_controller Quote Link to comment https://forums.phpfreaks.com/topic/263230-simple-calculations/#findComment-1349048 Share on other sites More sharing options...
luckyguys Posted May 27, 2012 Share Posted May 27, 2012 Will this code works with Add & Subtraction from DB : SELECT pay_controller, SUM(pay_amount) as total FROM payments GROUP BY pay_controller Quote Link to comment https://forums.phpfreaks.com/topic/263230-simple-calculations/#findComment-1349055 Share on other sites More sharing options...
DrTrans Posted May 27, 2012 Author Share Posted May 27, 2012 Im confused on how i would put this in my code. Quote Link to comment https://forums.phpfreaks.com/topic/263230-simple-calculations/#findComment-1349060 Share on other sites More sharing options...
Barand Posted May 27, 2012 Share Posted May 27, 2012 Will this code works with Add & Subtraction from DB : SELECT pay_controller, SUM(pay_amount) as total FROM payments GROUP BY pay_controller It will if pay_amount contains pos and neg values Quote Link to comment https://forums.phpfreaks.com/topic/263230-simple-calculations/#findComment-1349061 Share on other sites More sharing options...
DrTrans Posted May 28, 2012 Author Share Posted May 28, 2012 so the amounts have include the payment controller? so it would be +100.00 or -100.00 instead of 100.00 with a pay controller of + or -? is this correct? Quote Link to comment https://forums.phpfreaks.com/topic/263230-simple-calculations/#findComment-1349094 Share on other sites More sharing options...
ignace Posted May 28, 2012 Share Posted May 28, 2012 Yes Quote Link to comment https://forums.phpfreaks.com/topic/263230-simple-calculations/#findComment-1349132 Share on other sites More sharing options...
DrTrans Posted May 29, 2012 Author Share Posted May 29, 2012 Can you elaborate more details how i would put this in tablet form. to give the balance. Quote Link to comment https://forums.phpfreaks.com/topic/263230-simple-calculations/#findComment-1349390 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.