'PHP + MySQL Interval query last 1 month with sum problem

My aim is to sum the MBSENT and MBREC values from the last 1 month for every user.

This is the log (what i want to sum later):

USER  MBSENT MBREC  TRUSTEDIP   REMOTEIP        DATE            ID
csib    99  0   x.x.x.x.x   10.8.0.6    2015-03-04 12:19:14 3
csib    30  0   x.x.x.x.x   10.8.0.6    2015-03-04 12:22:02 4
kwai77  10  0   x.x.x.x.x   10.8.0.10   2015-03-04 12:23:22 5
kwai77  24  0   x.x.x.x.x   10.8.0.10   2015-03-04 12:28:18 6
kwai77  2   0   x.x.x.x.x   10.8.0.10   2015-03-04 13:15:29 7
csib    10  0   x.x.x.x.x   10.8.0.6    2015-03-04 14:32:01 8

This is my code:

$sql = "SELECT SUM(mbsent) AS summ FROM data WHERE datum < DATE_ADD(NOW(), INTERVAL -1 MONTH) AND user='csib'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    echo "<table><tr><th>MBSENT</th><th>user</th></tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["mbsent"]."</td><td>".$row["summ"]." </td></tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}

This is my code but not working, somehow as i see it is always returns with the first mbsent value. Not the SUM of the MBSENT value with user csib.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source