+ Reply to Thread
Results 1 to 30 of 35

Thread: PHP/SQL Highscores, avoiding duplicate entries

Hybrid View

  1. #1
    Senior Member
    Join Date
    Mar 2005
    Location
    Oliver Pearl Studio
    Posts
    460

    Default PHP/SQL Highscores, avoiding duplicate entries

    As you (probably ) know I'm running some webgames at my website, and they have global highscores. I'd like to get rid of duplicate entires having the same player name. Basically for a given name I'd like to keep the highest score only.

    I'm using an SQL database and wanted to know if the comparison/replace stuff can be made directly with the SQL command REPLACE? And if yes how? (I checked the SQL doc and I think the answer is no).
    I know I can do it with PHP but it would probably have a higher load on the server as I would have to first read the data, eventually delete a row and then write a new row.

    PS: Yes it's rather an easy method assuming each player would use a unique username, but I think setting up a login system would be over complicated.

  2. #2
    Senior Member
    Join Date
    Aug 2004
    Location
    Dorset, England
    Posts
    1,012

    Default

    If each player has a unique ID then it's quite simple but you will need to insert a score into the table if the player is not there already.

    Code to update :
    Code:
    UPDATE high_score_table
    SET score = 'nnn', level = 'nn'
    WHERE unique_id = 'user_id'
    Indiepath Ltd
    "do good things - make money"
    And that is not the general opinion of Indiepath Ltd - etc... legal .... blah..

  3. #3
    Senior Member
    Join Date
    Mar 2005
    Location
    Oliver Pearl Studio
    Posts
    460

    Default

    AFAIK my players don't have unique IDs. I'd be glad to know how to do it. For the moment I'm simply assuming each player would use a unique name (VARCHAR).

    As you guess I'm pretty new to SQL. According to the official doc I could use the INSERT command with the ON DUPLICATE KEY UPDATE statement, that would act like an UPDATE command.
    Anyway I think the main problem is comparing the old score with the new one?

  4. #4
    Member
    Join Date
    Oct 2004
    Location
    QLD, Australia
    Posts
    33

    Default

    I don't think running an extra SQL query on score submission is going to be a big server hit.

    Are you trying to stop a user constantly submitting a score from a single play session or are you trying to have one score per player? If you are doing the latter without unique user tracking i think you are going to a lot of trouble just to anoy players.

  5. #5
    Senior Member
    Join Date
    Mar 2005
    Location
    Oliver Pearl Studio
    Posts
    460

    Default

    I'm just trying to have one score per player. How to track users then?

    Would players really be annoyed to see only their highest score listed? Do some players *feel better* after having filled 10 entries in a row?

  6. #6
    Senior Member
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    230

    Default

    Why not let them submit multiple times? That way the player has a summary of their progress and for your _main_ scoreboard you can always do something along the lines of
    PHP Code:
    SELECT playerMAX(score) AS m_score FROM score_board GROUP BY player ORDER BY m_score 

+ Reply to Thread

Posting Permissions

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