add up mysql row and then echo the result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    add up mysql row and then echo the result

    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. 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_tim e min";
    ---------------------------------

    Result:

    60 min

    Thanks
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    What type of a column is it? DateTime? Int?

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, webandwe.

      Have a look at MySQL's date and time functions.

      Comment

      • webandwe
        New Member
        • Oct 2006
        • 142

        #4
        Hi, it is just a varchar....

        I have a script that converts the numbers into time....I just need to write a php script that add's up all the number and then echo it out...I will hande the results from there.

        Comment

        • entertainmentliveuk
          New Member
          • Aug 2007
          • 9

          #5
          Originally posted by webandwe
          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. 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_tim e min";
          ---------------------------------

          Result:

          60 min

          Thanks
          Try something like this:
          [PHP]
          $mins=0;
          $time = mysql_query("se lect * from $table WHERE Time> '0' ");
          {
          while($row = mysql_fetch_arr ay($time))
          {
          $mins=$mins+$ro w['Time'];
          }
          echo $mins." minutes";
          [/PHP]

          Comment

          Working...