Reputation: 51
I am making a site which allows admins to basically add points for a user.
At this point in time, I have a table, where id_child
is unique, and id_points
changes. So a constant stream of id_points
can come in, however, it will only show the latest id_points
, not the total.
I am wondering how I could go about creating a PHP script that could add all of those together.
From the image, the idea is that I want all id_points values added together to give a total, and this is for the same id_child
Upvotes: 0
Views: 79
Reputation: 609
Hope i understood right.
First if you want to show only the latest points added you have to create another table #__points
where you will keep every new change of points.
You need 3 columns id
as PRIMARY
and AUTO_INCRENMENT
, pts
and user_id
. user_id
will be FK to id_child
.
So when you want to add a new record :
INSERT INTO `#__points` (pts,user_id) VALUES ("$pts",$id)
When you want to select last inserted value for each admin :
SELECT * from `#__points` where user_id=$id ORDER BY id ASC LIMIT 1
Upvotes: 1
Reputation: 92471
Use SQL sum()
funciton:
select sum(id_points) from table `table_name` where `id_child` = 1
Upvotes: 1