php - Day by day summing of values from a table -
i have script gathers data , table structure
date - y-m-d h:i:s name - example quantity - 1 example id - date - name - quantity 1 - 2015-05-13 16:33:09 - test1 - 1 2 - 2015-05-13 19:10:45 - test2 - 3 3 - 2015-05-13 22:01:39 - test3 - 1 4 - 2015-05-14 07:13:20 - test4 - 1 5 - 2015-05-14 09:29:37 - test5 - 2 how can add quantity on same date 2015-05-13 day day output data in text format: 5, 3 ......
require_once 'config.php'; $mysqli = new mysqli($server, $db_user, $db_password, $database); if ($mysqli->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "select id, date, quantity downloads"; $result = $mysqli->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo $row["quantity"]. "<br>"; } } else { echo "0 results"; } $mysqli->close();
use query sum of quantities per date
select date(`date`), sum(quantity) downloads group date(`date`) it group results date part of datetime column date , provide sum of quality column every date.
date function explanation: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date
sum function explanation: https://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_sum
Comments
Post a Comment