Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:05:36+00:00 2026-06-04T07:05:36+00:00

What is the best way to structure a Virtual Credits System in PHP/MySQL? I

  • 0

What is the best way to structure a Virtual Credits System in PHP/MySQL?

I would obviously need one table for each Transaction (debit/credit). I’m thinking I would need the following columns in that table:

  • TransactionID (unique transaction ID starting at 1 with Auto-Increment)

  • UserID (users unique ID from the main Users table)

  • Type (earned, purchased, spent, etc.)

  • ItemID (if spent on an item)

  • Amount (positive or negative).

QUESTIONS:

1) Do I need any other columns in this Table?

2) Do I need any other Tables for this purpose?

For example, would I need another table to keep track of each user’s total? Or would I simply calculate each user’s total as the sum of all their transactions?

At first, this Credit System will be purely “play money”, but I do expect to add a “Buy Credits” option in the future, so perhaps I should add a column for the 3rd party payment processors Unique Transaction ID ? Or should I create a separate table for purchased Credits, and then tie the two together via my script (e.g. total credits = earned credits + purchased credits – spent credits)?

On top of answering my questions above, I would appreciate any and all insight and ideas, including links to specific articles on how to go about this, as I’ve never programmed anything like this before.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:05:36+00:00Added an answer on June 4, 2026 at 7:05 am

    Some notes.

    I think if you want to build a solid system that handles finances, it makes sense to use some basic concepts from financial world. I don’t want to say you have to completely implement all accounting features, but many things seem reasonable to me.

    First of all, financial transaction involves moving money from one account to another, so instead of user_id I’d use account_id. Each user may have more than 1 account , each account has a type (lookup), and currency. Also, I’d avoid term “user” in favor of “party” (party-role-relationship model).

    Secondly, there are always at least 2 parties involved : money moves from one account to another. In case of item purchase , person’s account balance decreases, and organization account balance increases.

    Also, I’d not use item_id, but something like event_id . Each transaction is associated with one business event. Event is a common parent table for various events which may occur in your system. Each of Event‘s detail table will hold information specific to event type. For instance, you can have purchase_event , deposit_event, etc.

    Because transaction table is a subject of many (potentially thousands) inserts, I wouldn’t query it every time you need account balance. It makes sense to keep consolidated balance in account table.

    I hope that makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the best way to structure a MySQL table for storing admin settings? Like
What is the best way to translate the following problem in SQL table structure:
What would be the best way to structure orders for a restaurant (available languages
What is the best way of defining in C# a structure with, say, 6
The best way of describing this is I have a table of people with
The best way to store images into MySQL is by storing the image location
I'm trying to figure out the best way to structure my data in Mongo
Really like objectify, although still struggling with what is the best way to structure
I'm wondering about the best way to structure authentication/authorization in my app. I want
I am trying to decide the best way to structure some code. I will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.