Idea/approach: adding data on database when condition met

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
xkevin
Forum Newbie
Posts: 14
Joined: Thu Jun 09, 2016 9:01 pm

Idea/approach: adding data on database when condition met

Post 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.
Last edited by xkevin on Tue Jun 14, 2016 12:46 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
xkevin
Forum Newbie
Posts: 14
Joined: Thu Jun 09, 2016 9:01 pm

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

Post 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.
Post Reply