sum

Discussion in 'PHP' started by harryoxford, Sep 18, 2009.

  1. #1
    GET SUM WHERE in between...
    I'm trying to only get SUM of fields with an WHERE clause with between numbers...

    PHP Code:


    $sql1="SELECT SUM(*) as par_out FROM ".$prefix."_turn_data WHERE turnid=$sturn AND hole_no > 0 AND hole_no < 10";



    Something is wrong here, but cant figure out what?

    Any help apreciated...
     
    harryoxford, Sep 18, 2009 IP
  2. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Post the entire code bit you are using, not just the variable containing the SQL query (so post your mysql_query command and what you are doing with the result afterward).
     
    Christian Little, Sep 18, 2009 IP
  3. pubdomainshost.com

    pubdomainshost.com Peon

    Messages:
    1,277
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You query to get data between two values is incorrect, thus the anomaly or problem in getting right result set.
    You should use BETWEEN - as shown below

    More Help : Google "MySQL BETWEEN"

    Cheers
     
    pubdomainshost.com, Sep 18, 2009 IP
  4. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes he should, but that won't break a mysql command. I don't see any syntax errors with what he's using, which leads me to believe it's what he's doing with the results once he's run the query.
     
    Christian Little, Sep 18, 2009 IP