SUM function problem

Discussion in 'PHP' started by adsegzy, Aug 4, 2010.

  1. #1
    Hello friends,

    am having problem with my SUM function. I tried summing up some figures in a column but is not returning the total of the figures. this is my syntax



    <?php
    include("config.php");
    $column='amount';
    $table='transactions'
    $creditbal=mysql_query("SELECT SUM($column), FROM $table WHERE status='P'");
    $rows=mysql_fetch_array($creditbal);
    echo $creditbal;
    ?>

    but is not echoing any out any, what can i do.

    Regards,
    adsegzy
     
    adsegzy, Aug 4, 2010 IP
  2. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #2
    try this:
    
    
    <?php
    include("config.php");
    $column='amount';
    $table='transactions';
    $creditbal=mysql_query("SELECT SUM($column), FROM $table WHERE status='P'");
    $rows=mysql_fetch_array($creditbal);
    echo $rows;
    ?>
    
    PHP:
     
    arpit13, Aug 4, 2010 IP
  3. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #3
    "SELECT SUM($column), FROM $table WHERE status='P'"
    ^ try removing the comma
     
    bartolay13, Aug 4, 2010 IP
  4. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #4
    woops didn;t noticed that "," ya remove it and then try my code.
     
    arpit13, Aug 6, 2010 IP
  5. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #5
    When your developing a script, you should have it setup to show you errors. Place or die (mysql_error()) at the end of all of your functions that way if there is a problem with the SQL code it will let you know, rather then just return nothing.

    Glen
     
    HuggyEssex, Aug 6, 2010 IP