Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2010

    Unanswered: need help with simple database

    unsure how I can do this, i am fairly new at PHP, I am still learning and have self taught myself from reading ALOT.

    My question is how can I have my registered users receive a code in their email a three digit code, that is pulled from a data base of 999 codes, that can only be used once? it selects a new code each time.
    Also there will be referers so if code 011 refers a friend their friends will say yes 011 referred me and the database will keep track of any linked codes from referrals.

    Seems way out of my league if anyone can help please let me know.
    I appreciate all the help I can get thank you!


  2. #2
    Join Date
    Jul 2010
    Winnipeg, Canada
    Pretty simple, you have a couple options. One simple solution is to have a table with all the possible codes and a field for the username/id/identifier of the person who consumed the code.

    For example, [code_id], [user_id]

    As such, you can simply query the table for a row with an empty [user_id] to access a new unused code. Additionally, in the table with users (assuming you have one), keep a [referral_code] column with the code that the person was referred by. Subsequently you can aggregate referrals with simple queries thereafter.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts