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 6943587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:10:33+00:00 2026-05-27T13:10:33+00:00

I realize this might be a confusing question so I will try and explain

  • 0

I realize this might be a confusing question so I will try and explain further.

I have been tasked with creating a Facebook competition tab on our page for users to click on a box and to be given a random prize.

There is going to be a finite number of each prize and one major prize.

I am just thinking of the best way to structure and implement this.

All I can think of is a database table to store the prizes with id, name, value and number_available.

Then, when the user clicks the box, a random number is generated between the min and max id’s of the table, look up the db row with that id and check if there are any available, if there are, print out the details for the prize. If there’s not any of that prize available then keep going until we get a prize that’s still in ‘stock’.

I think that’s not a bad way to do it but not efficient when it comes down to relying on there being some of a particular prize left. If for example there were only one or two prizes left it could take a while for the right random number to be generated for prizes that are left.

The other thing that is bothering me is the major prize. Should I leave it to chance and just let it be won fair and square as soon as that random number is generated or should there be some kind of weighting applied to it to stop it being won quickly (competition is going to run until the end of the month)?

Then, if yes, how should I apply some kind of weighting?

  • 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-05-27T13:10:34+00:00Added an answer on May 27, 2026 at 1:10 pm

    Surely you don’t need to keep repeating the query?

    Your query would be something like:

    SELECT * FROM `prizes` WHERE `number_available`>0 ORDER BY RAND() LIMIT 1
    

    Then after it pulls that prize out it’d update the table to set number_available to number_available-1:

    UPDATE `prizes` SET `number_available`=`number_available`-1 WHERE `id`='ID'
    

    In which case it wouldn’t need to repeat? Once the number_available is 0 then it’s not part of the query anymore.

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

Sidebar

Related Questions

I realize this is a basic question but I have searched online, been to
I realize that this is a question that will probably not have a single
I realize this might be an easy question that I may have overlooked in
I realize this might be a long shot, but does anyone have an example
Greets. I realize this might be seen as a duplicate question as this but
I realize this question might not be that programming related, and that it by
Upon pre-submission review, I realize this question might be incredibly silly. if (this.gameOver(gpos) >
the title of this post might be confusing.I'll try be best to clarify it.
I realize that this might be a duplicate question but this question is very
I realize this perhaps a naive question but still I cant figure out how

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.