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 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    add up all mysql rows and then echo it out in php..

    Hi,

    I have a database with a row called "time".

    I need to somehow add up all the time rows and then echo out the total in php. How do I do it?

    Example

    MySQL
    -----------
    1. time 30
    2. time 10
    3. time 20

    php
    ----------------


    $total_time = ( addup all SQL rows FROM Time);

    echo"$total_time min";
    ---------------------------------

    Result:

    60 min

    Thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Code:
    SELECT SUM(time_column)
    FROM your_table
    If you are unsure how to do a MySQL query in PHP, refer to the manual, mysql_query() function. Very simple code example on that page.


  •  

    Posting Permissions

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