Page 1 of 1

Idea/approach: adding data on database when condition met

Posted: Mon Jun 13, 2016 11:19 pm
by xkevin
I am trying to add some line of code on my website, maybe "require_once( 'point_counter.php' );".

Every client has details "user" table (name,email,totalproduct, totalsales, totalwithdrawn etc..)

Now I am adding one column to the database table and name it as 'total points':

What I would like to do:
In the code 'point_counter.php', when a user login successfully, it adds points to the database when conditions met:
e.g:
-A = if user has active products add +20 to the total points.
-B = if user completed withdrawal then add +20 to the total points.
-and some other conditions.

My problem is, what if the user login (first) then met the A condition (added 20 points), Then logout and login again(second) and so on..(probably it will add and add again and again).

What would be the logic that when A condition already met or already added points then It will not add again. Instead , jump to other conditions that had no points.

What is the best approach to do this with only 1 column to the database for points.

Re: Idea/approach: adding data on database when condition me

Posted: Mon Jun 13, 2016 11:29 pm
by requinix
The points should be updated when the events happen: when they get active products and when they complete withdrawals. When you add this column you set it to have the correct number of points at the same time (ie, ALTER to add the column then UPDATE to calculate the correct points). Nothing should need to happen just because they logged in.

Re: Idea/approach: adding data on database when condition me

Posted: Tue Jun 14, 2016 12:55 am
by xkevin
requinix wrote:The points should be updated when the events happen: when they get active products and when they complete withdrawals. When you add this column you set it to have the correct number of points at the same time (ie, ALTER to add the column then UPDATE to calculate the correct points). Nothing should need to happen just because they logged in.
-That make sense. But some additional events to the client and to the system. The product have cycle dates. example cycle 1(may 2015), cycle 2(Sep 2015), cycle 3(Jan 2016).. etc. So when the cycle is open the clients can add products. The problem with the event is, it can be repeated. So it will again add another points which should not. My solution for this is to just add different field for the points. Column for product points and another for withdrawal(it would be easy).. But I want to do it with just one column if possible.