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

  • Home
  • SEARCH
  • 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 621991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:56:09+00:00 2026-05-13T18:56:09+00:00

For a browser game, I have a database table fights : fightID fromID toID

  • 0

For a browser game, I have a database table fights:

  • fightID
  • fromID
  • toID
  • simulated (1=true, 0=false)

Whenever a user requests a page, I select all fights which still have to be simulated:

SELECT fightID, fromID, toID FROM fights WHERE simulated = 0

These outstanding fights are then simulated in the PHP script and, finally, the fight is marked as simulated and the winner gets his points:

UPDATE fights SET simulated = 1 WHERE fightID = X
UPDATE users SET points = points+1 WHERE userID = WINNER

The problem:

Imagine two users coming to the page one after another in only a few milliseconds. On both users’s page load the same outstanding fights are selected. Then they are simulated and – since both requested the page almost at the same time – the winner gets his points twice. The fights are then marked as simulated. But this is too late.

How can I avoid this problem? Thank you very much!

  • 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-13T18:56:09+00:00Added an answer on May 13, 2026 at 6:56 pm

    If you are sure that once you read the fights from the DB, they will be simulated (i.e. it is not possible that the user quits and that some fights are left unsimulated), you an use a transaction to read and update the fights in one, atomic operation.

    START TRANSACTION;
    SELECT fightID, fromID, toID FROM fights WHERE simulated = 0
    UPDATE fights SET simulated = 1 WHERE fightID = X
    COMMIT;
    

    and then later update the scores.

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

Sidebar

Related Questions

I want to detect multi accounts in a browser game: If a user has
I have a Flash based game for the browser which sends users' scores to
I run a browser based game at www.darknovagames.com. Recently, I've been working on reformatting
I'm considering using Django for a project I'm starting (fyi, a browser-based game) and
I am designing a game to be played in the browser. Game is a
I'm attempting to write a browser game using Django but I'm getting a bit
Does someone have any tips/advice on database design for a web application? The kind
So I have this database class in PHP and I only have 1 function
I'm creating a humble web browser-game in PHP. I'm making a robbery section... I
I am building a browser game with a mini map of the surroundings of

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.