jbwebdesign Posted January 12, 2010 Report Share Posted January 12, 2010 Hello.....I am working on a script that will pull the data from a db and I am having some trouble.....I was wondering if someone can help me out. I have a db with a field called payment_amount. i would like to add * FROM payment_amount. does anybody have any idea on how i can add the total amount?? here is what i have: //connect to the db connect(); //build query $history = mysql_query("SELECT * FROM payments"); $my_rows; //create a while loop to show all records while($row = mysql_fetch_array($history,MYSQL_ASSOC)){ $my_rows = $my_rows . $row['payment_amount']; //here i will add the total amount paid =) $total = ""; //---set default value for total amount paid $row['payment_amount']+= $total; } echo $my_rows; echo $total; Quote Link to comment Share on other sites More sharing options...
BeeDev Posted January 13, 2010 Report Share Posted January 13, 2010 $total = ""; //---set default value for total amount paid BEFORE THE LOOP //create a while loop to show all records while($row = mysql_fetch_array($history,MYSQL_ASSOC)){ $my_rows = $my_rows . $row['payment_amount']; //here i will add the total amount paid $total += $row['payment_amount']; // Changed the $total and $row around } Not tested. But I think this is what you want to do? Quote Link to comment Share on other sites More sharing options...
jbwebdesign Posted January 13, 2010 Author Report Share Posted January 13, 2010 I found my problem I needed to change MySQL query. I didn't know that there was a MySQL query to SUM up the values in a colum. but I found it on tizag 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.
Note: Your post will require moderator approval before it will be visible.