Hello and welcome to our community! Is this your first visit?
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
    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
    Join Date
    Jun 2003
    Cottage Grove, Minnesota
    Thanked 1,096 Times in 1,087 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:

    "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)){
    "Total "$row['Code']. " = "$row['SUM(amount)'];
    "<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