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
    Regular Coder
    Join Date
    Sep 2010
    Posts
    119
    Thanks
    6
    Thanked 0 Times in 0 Posts

    php table sum logic need

    hi again

    i have a table with

    Po no | Code | amount | SUM

    Po-1 TT-2 5
    Po-1 TT-2 10
    Po-1 TT-2 15
    Po-1 TT-2 10......... 40
    Po-1 TT3 5
    Po-1 TT3 5 ......... 10

    how do i get the SUM of each code TT-2 amount total as 40 and TT-3 amount total as 10

    plz give me a logic for with sample code

    this above data come from database alsooooooooooo

    plz provide sample code for this

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,380
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    This is an untested shot at your query ...

    In this example, your table name is "tablename" ...
    and the variable names as you provided (not sure if they are correct or not) ...

    PHP Code:
    <?php

    $query 
    "SELECT `Po no`, `Code`, SUM(`amount`)" .
       
    "FROM tablename " .
       
    "GROUP BY `Code`" .
       
    "ORDER BY `Code` DESC";
            
    $result mysql_query($query);

    // Print out result
    while($row mysql_fetch_array($result)){
        echo 
    "Total "$row['Code']. " = "$row['SUM(amount)'];
        echo 
    "<br />";
    }

    ?>


  •  

    Posting Permissions

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