Reputation: 18198
Let's say I have this table in my database:
Each time
is a UNIX timestamp that range from December 6 to December 14(today). Some rows have the same day but not the same time (ie: Dec 14 8:39PM, Dec 14 10:21 PM) and such.
However, I'm trying to make a mysql query that will add up all gained
points for each day.
I currently have a while
list that goes down the list sorted by uid
because UID
is the id
of the user.
This is my currently while
query:
$get_statuses = mysql_query("SELECT * FROM `history`
WHERE `uid` = '$logged[id]'
ORDER BY `id` DESC LIMIT 50");
Assuming I use this $fullDate = date("F j, Y", $status['4']);
for each current loop beacuse I did this while ($status = mysql_fetch_array($get_statuses)) {...}
, how do I do this?
Maybe a SELECT(SUM)
?
Upvotes: 0
Views: 179
Reputation: 57650
Use this query.
SELECT Date(From_unixtime(`time`)) AS `Date`,
Sum(`gained`)
FROM `tbl`
WHERE `uid` = '$logged_id'
GROUP BY `Date`
ORDER BY `id` DESC
You can add More where condition here. Like
From_unixtime(`time`) >= '2012-12-06'
AND
From_unixtime(`time`) <= '2012-12-14'
Upvotes: 2