Jump to content


Photo

Comparing data to be inserted to database rows


  • Please log in to reply
4 replies to this topic

#1 jackal

jackal
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 12 January 2006 - 10:54 PM

I create computer games in my spare time and I wanted to create an online high score board for my newest game. I am pretty new to php and mysql. I have been able to stumble my way thru creating the database, table, inserting the data from my game, and retrieving/displaying the scores. Here is the [a href=\"http://www.brainpanreviews.com/bustin_balls_highscores/index.php\" target=\"_blank\"]score board[/a]. As you can see there are several entries with jason 98 as the name and score. This is because I realized that hitting refresh resubmitted and posted over and over. To avoid this, I want the php script to check the database before inserting the new name and score. All I am worried about is checking that the same name and score don't appear together. I am not sure how to check the new name and new score to be submitted against the database rows.

I am not sure what is the best way to go about this without having the player register, use cookies, etc.
I would appreciate suggestions, examples, or code.

Thanks for any help.

jackal

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 January 2006 - 12:29 AM

Well, there are two ways -- first, assuming that the "name" is unique, you could always issue a REPLACE instead of an INSERT statement. Second, you could simply only output the results grouped by name, and take the most recent entry. Personally, I think the latter makes more sense.

Hope that helps.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 jackal

jackal
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 January 2006 - 12:52 AM

I see what you mean but there is no way that the names will be unique. There may be 20 different jason's with 20 different scores, this score board is only for everyone to view the top scores and therefore all I am worried about is someone "spamming" the list using the refresh button.

I've been thinking about looping over the table and comparing names and scores. But I can't quite figure out how I would/should do this.


#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 January 2006 - 12:58 AM

The only other way to do this is redirect after the post, so that refreshing the page just shows the output again, but doesn't post again. Otherwise, you're out of luck if you can't uniquely define your users.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 jackal

jackal
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 13 January 2006 - 09:25 PM

I thought of that but I wasn't sure if the player would be able to use the "back" button and refresh the previous page which would then post/insert again. I think you're right and this is the best cure. I will start searching on how to redirect.

Thank you very much.

jackal




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users