Answer the question
In order to leave comments, you need to log in
Assigning indexes to rows in a table
There is a mySQL database, there is a table with a leaderboard. It has an id field, an account and a position. The user with the ID updates his account, the database must recalculate his position. There are no problems here: I take a player with a minimum score from the players with a higher score than mine, add one to his position and write it down. But at the same time, the positions of players with positions equal to or less than mine are violated. Is there a way to update the position of all players in one request?
PHP is driving the whole thing.
Answer the question
In order to leave comments, you need to log in
UPDATE `board`
SET `position`=`position`+1
WHERE `position`>='$myPosition' AND `id`<>'$myID'
SELECT COUNT(`b`.`id`) AS `position`
FROM `board` AS `b` JOIN `board` AS `my`
ON(`b`.`scores`>`my`.`scores` OR (`b`.`scores`=`my`.`scores` AND `b`.`id`<`my`.`id`))
WHERE `my`.`id`='$myID'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question