How do I add value of field in all mysql to one?

Discussion in 'PHP' started by HolmesAndHarris, Jul 1, 2008.

  1. #1
    Hi guys,

    I found the forum from Google so I hope you can help?

    At present, I have a mysql table with lots of rows.

    One of the rows contains a field called "fee".

    Now what I want to be able to do is add up all values of "fee" throughout the table.

    I.e:

    Structure:
    Name, RoadName, Country, Telephone, Fee

    Example Rows:
    John Smith, 1234 Test Road, UK, 1234567890, 5.00
    Joe Blogs, Another Test Road, UK, 111111111, 10.00
    Sarah Roberts, Final Test Road, USA, 12345678, 20.00

    Desired Outcome:
    Total Fee: 35

    Please can anyone advise on how to do this/example code??

    Much appreciated
    Regards
    Chris
     
    HolmesAndHarris, Jul 1, 2008 IP
  2. Nextri

    Nextri Member

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    SELECT SUM(fee) FROM table;
     
    Nextri, Jul 1, 2008 IP
  3. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #3
    $query = 'SELECT SUM(fee) as total_fee FROM yourtablename';
     
    php-lover, Jul 1, 2008 IP
  4. lightningzeus

    lightningzeus Peon

    Messages:
    188
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes this should do it
     
    lightningzeus, Jul 1, 2008 IP