/    Sign up×
Community /Pin to ProfileBookmark

Help with adding transaction tracking data

The php video web script that I’m trying to modify has a process where Users generate credit units from viewed videos.
The total ‘balance’ of credits is stored in mysql db table named ‘User’, in a column titled “balance”, with each total reflected in a users’ row, and the ‘balance’ total gets updated (goes up or down), depending on the activity of the credits.

However, if 2 credits get added to the balance, for example, there is no tracking of what type of activity caused the balance total change.

I believe a separate table that gets a new row inserted for each transaction, that affects the amount, should be created? but I don’t know how to go about doing that. Any guidance you’d like to share is appreciated.
What else might this need? Or do you have a better/another idea?
I look forward to all comments/suggestions.

to post a comment

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 14.2019 — > @chrisjchrisj#1610047 I believe a separate table that gets a new row inserted for each transaction, that affects the amount, should be created?

Yes. It's even possible you then would not put the balance in the users table, but would calculate it on the fly by querying this new table. (It would therefore need to include a user_id column along with whatever else goes in it.)
Copy linkTweet thisAlerts:
@chrisjchrisjauthorOct 14.2019 — Thanks for your reply. Much appreciated.

However, I don't understand " calculate it on the fly by querying this new table"

could you expand on that?
Copy linkTweet thisAlerts:
@NogDogOct 14.2019 — @chrisjchrisj#1610061

The simplest thing would be to add a row to this new table each time a user earns (or loses?) credits. If we start with a really simple example, maybe it's just 3 columns: user_id, transaction_timestamp, and credits. (Additional columns might have other details such as a reference to a video ID, etc.). If I want to know how many credits user 123 has:
<i>
</i>SELECT SUM(credits) AS current_credits FROM credit_table WHERE user_id = 123;
×

Success!

Help @chrisjchrisj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...