DrTrans Posted April 14, 2010 Share Posted April 14, 2010 Property Amount Test 100 Test 300 Test 500 I want to be able to add up all fields of Amount By Property so it gives me a value of ex. 900. my code $query9 = "SELECT SUM(Amount) FROM gldetail Where Property_ID = '$prop'"; $result9 = mysql_query($query9); echo"$result9"; $sum = mysql_fetch_assoc($result9); $sum2 = $sum['Amount']; $sum3 = number_format($sum2,2); Thanks for your help. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Change $query9 = "SELECT SUM(Amount) FROM gldetail Where Property_ID = '$prop'" To $query9 = "SELECT SUM(Amount) as amount FROM gldetail Where Property_ID = '$prop'" Then change $sum2 = $sum['Amount']; To $sum2 = $sum['amount']; Quote Link to comment Share on other sites More sharing options...
DrTrans Posted April 14, 2010 Author Share Posted April 14, 2010 I keep getting a value of "0" i dont know why there are tons of amounts in my database some of them with "-" next to the first number, so amount could be -357.00" could this be why im getting a "0" Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Is the column set to type int? Quote Link to comment Share on other sites More sharing options...
DrTrans Posted April 14, 2010 Author Share Posted April 14, 2010 Negative. its set to "float" Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 After $query9: echo $query9; Copy and paste that here please. Quote Link to comment Share on other sites More sharing options...
DrTrans Posted April 14, 2010 Author Share Posted April 14, 2010 Resource ID: #3 is the responce. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 o.O ... what? Paste your updated code here please. Quote Link to comment Share on other sites More sharing options...
DrTrans Posted April 14, 2010 Author Share Posted April 14, 2010 $connect = mysql_connect("localhost","root",""); mysql_select_db("tenantpro"); $rentid ="6"; $query9 = "SELECT SUM(Amount) as amount FROM gldetail WHERE Property_ID = '$prop'"; echo "$query9"; $result9 = mysql_query($query9); echo "$result9"; $sum = mysql_fetch_assoc($result9); $sum2 = $sum['amount']; Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2010 Share Posted April 14, 2010 You already have an existing thread for this problem, where someone already suggested echoing the query statement and executing that query directly against your database. For the code you have shown, echoing the $query9 variable cannot give the result you just posted. What is your real code? And the answer to your problem is that either your query is failing due to an error in the query or with the database server or your WHERE clause in the query is matching no rows. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Remove the echo "$result9"; line please and paste what my echo $query9; outputs to the screen. Quote Link to comment Share on other sites More sharing options...
DrTrans Posted April 14, 2010 Author Share Posted April 14, 2010 $prop = $_GET['prop']; $connect = mysql_connect("localhost","root",""); mysql_select_db("tenantpro"); $rentid ="6"; $query9 = "SELECT SUM(Amount) as amount FROM gldetail WHERE Property_ID = '$prop'"; echo $query9; $result9 = mysql_query($query9); $sum = mysql_fetch_assoc($result9); $sum2 = $sum['amount']; Responce: SELECT SUM(Amount) as amount FROM gldetail WHERE Property_ID = '435' Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 From the table, looks like it should add up to 0. :-\ Quote Link to comment Share on other sites More sharing options...
DrTrans Posted April 14, 2010 Author Share Posted April 14, 2010 thats only partial. though Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 And when you echo $sum2; you get 0? 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.