0

I have a table with all my invoices, where I save the date as a TIME STAMP and the total value of the invoice.

I want to make a graphic based on the sales that needs the day and the value. But in the table there are more totals per day, so I made the query to get the rows from the current month and I get an output something like :

Date: 1403739780 / Value : 2167

Now I want to know how to group the values in one that are from the same day ( in PHP ) but I don't know any simple way.

Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82
Robert Voicu
  • 74
  • 1
  • 11
  • possible duplicate of [MySQL Query GROUP BY day / month / year](http://stackoverflow.com/questions/508791/mysql-query-group-by-day-month-year) – M Khalid Junaid Jun 29 '14 at 17:41
  • I made the query how to get the results by current month now I have many rows returned and need a way to sort them in an array or something by Day and total value of that day .... in PHP not mysql – Robert Voicu Jun 29 '14 at 17:43
  • 2
    Then why does the question have a MySQL tag? – shmosel Jun 29 '14 at 17:45

1 Answers1

0

you can use the timestamp as the key of the array:

$mysqli = new mysqli("localhost", "user", "pass", "database");
$result = array();
$sql = "SELECT ...";
$result = $mysqli->query($sql);
while ($row = $result->fetch_assoc()) {
    $day = date("Ymd", $row["timestamp"]);
    $result[$day] += $row["value"];
}
chresse
  • 5,486
  • 3
  • 30
  • 47