Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post

    adding mysql results

    i have a query that selects rows from a db and i need it to add the prices together in the database and then output them for the Totals: section. is there a function that does this?

  • #2
    Regular Coder dswimboy's Avatar
    Join Date
    Nov 2003
    Location
    mostly in Ann Arbor
    Posts
    458
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    while ($thisrow mysql_fetch_array($result)) {
       
    $total =+ $thisrow['cost'];

    "There is more than one way to do it."

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you only need the totals (so if you don't print out the individual records) then doit in sql. Like

    SELECT sum(cost) as totalcast, productID FROM table GROUP BY productID

    you can then acces the total for each 'productID' (or whatever variable your grouping on) with $row['totalcost']
    if you leave off the GROUP BY clause and remove the productID from the fieldslist, then you get the total of all records.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •