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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:23:37+00:00 2026-06-06T13:23:37+00:00

I have a web page where people are able to post a single number

  • 0

I have a web page where people are able to post a single number between 0 and 10.

There is like a lotto single number generation once daily. I want my PHP script to check on the the posted numbers of all the users and assign a score of +1 or -1 to the relative winners (or losers).

The problem is that once I query the DB for the list of the winning users, I want to update their “score” field (in “users” table). I was thinking of a loop like this (pseudocode)

foreach winner{
    update score +1
}

but this would mean that if there are 100 winners, then there will be 100 queries. Is there a way to do some sort of batch inserting with one single query?

Thanks in advance.

  • 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-06T13:23:40+00:00Added an answer on June 6, 2026 at 1:23 pm

    Let’s just assume we have a datatable named posts and users.
    Obviously, users contain the data of the gambler (with a convenient id field and points for the number of points they have), and posts contain the post_id ID field for the row, user_id, which is the ID of the user and value, the posted number itself.

    Now you only need to implement the following SQL queries into your script:

    UPDATE users INNER JOIN posts ON users.id = posts.user_id SET users.points = (users.points + 1)
    WHERE posts.value = 0;

    Where 0 at the end is to be replaced with the randomly drawn number.

    What will this query do? With the INNER JOIN construct, it will create a link between the two tables. Automatically, if posts.value matches our number, it will link posts.user_id to users.id, knowing which user has to get his/her points modified. If someone gambled 0, and his ID (posts.user_id) is 8170, the points field will update for the user having user.id = 8170.

    If you alter the query to make it (users.points - 1) and WHERE posts.value != 0, you will get the non-winners having one point deducted. It can be tweaked as much as you want.

    Just be careful! After each daily draw, the posts table needs to be truncated or archived.

    Another option would be storing the timestamp (time() in PHP) of the user betting the number, and when executing, checking against the stored timestamp… whether it is in between the beginning and the end of the current day or not.

    Just a tip: you can use graphical database software (like Microsoft Access or LibreOffice Base) to have your JOINs and such simulated on a graphical display. It makes modelling such questions a lot easier for beginners. If you don’t want desktop-installed software, trying out an installation of phpMyAdmin is another solution too.


    Edit:

    Non-relational databases

    If you are to use non-relational databases, you will first need to fetch all the winner IDs with:

    SELECT user_id FROM posts WHERE value=0;
    

    This will give you a result of multiple rows. Now, you will need to go through this result, one-by-one, and executing the following query:

    UPDATE users SET points=(users.points + 1) WHERE id=1;
    

    (0 is the drawn winning number, 1 is the concurrent id of the user to update.)

    Without using the relation capabilities of MySQL, but using a MySQL database, the script would look like this:

    <?php
    $number = 0; // This is the winning number we have drawn
    
    $result = mysql_query("SELECT user_id FROM posts WHERE number=" .$number);
    
    while ( $row = mysql_fetch_assoc($result) )
    {
        $curpoints_result = mysql_query("SELECT points FROM users WHERE user_id=" .$row['user_id']);
        $current_points = mysql_fetch_assoc($curpoints_results);
    
        mysql_query("UPDATE users SET points=" .($current_points['points'] + 1). " WHERE user_id=" .$row['user_id']);
    }
    ?>
    

    The while construct make this loop to run until every row of the result (list of winners) is updated.

    Oh and: I know MySQL is a relational database, but it is just what it is: an example.

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

Sidebar

Related Questions

I have a web page which I want people to be able to upload
I have a web page in which people go to register for my site.
I have web page in PHP which displays all records in a table. I
I have web page which is passing a querystring parameter to page 2: <a
new on rails and using windows for now,, i have web page that user
I have web forms page that has 2 controls. A gridview and an associated
I have a web page that prompts for user input via DropDownLists in some
I have a web page where I show the details of an SSL certificate
I have a web page that whenever your in a text-field, if you hit
I have a web page that I display in a WPF WebBrowser control within

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.