How to count database value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    How to count database value

    I want to get the some of all values in given date range. This is my code and it prints all data correctly. But couldn't get the sum. Please tell me what is wrong?

    [PHP]$q = mysql_query("SE LECT * FROM db WHERE SID = '$SID' AND Date BETWEEN '$DateFrom' AND '$DateTo'");
    //echo $Date;
    while($row = mysql_fetch_arr ay($q)){
    foreach( $row AS $key => $val ){
    $$key = stripslashes( $val );
    }
    $Riml=$row["Rim"];
    count ($Rim);
    echo $Rrim;

    }

    }[/PHP]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by ghjk
    I want to get the some of all values in given date range. This is my code and it prints all data correctly. But couldn't get the sum. Please tell me what is wrong?

    [PHP]$q = mysql_query("SE LECT * FROM db WHERE SID = '$SID' AND Date BETWEEN '$DateFrom' AND '$DateTo'");
    //echo $Date;
    while($row = mysql_fetch_arr ay($q)){
    foreach( $row AS $key => $val ){
    $$key = stripslashes( $val );
    }
    $Riml=$row["Rim"];
    count ($Rim);
    echo $Rrim;

    }

    }[/PHP]
    I think mysql_num_rows( ) is what you're after:
    [php]
    $_query =
    mysql_query("
    SELECT
    *
    FROM
    `tbl_name`
    WHERE
    `tbl_col`
    =
    '{$_something}'
    "; # lets say this affects 4 rows in the table `tbl_name`

    $_num_rows = mysql_num_rows( $_query)

    echo "Rows affected: {$_num_rows}";
    [/php]

    Comment

    Working...