Jump to content

HOW TO COUNT USING PHP AND MYSQL


jbwebdesign

Recommended Posts

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;

Link to comment
Share on other sites

$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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...