Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-11-2014, 11:02 PM
prozacboy666 prozacboy666 is offline
Registered User
Join Date: Mar 2002
Posts: 130
prozacboy666 will become famous soon enough
Use SQL. Here is how I would do it.
When a new score comes in do a select on the database for the minimum score to get into the top20.
PHP Code:
SELECT MIN(scoreFROM myTable
If new score > min, insert new score into the database and delete the min score.
The only thing is you would have to do two queries to delete the min score from the database something like
PHP Code:
minId SELECT id FROM myTable WHERE score = (SELECT min(scoreFROM myTable)
DELETE FROM top20 WHERE id minId 
Then all you have to do is selects on that table if you are looking for the top20
PHP Code:
SELECT FROM top20 ORDER BY score DESC 
You probably could get the ID and delete it from the database all in one query but this should be fast enough.
Reply With Quote
  #2  
Old 12-12-2014, 08:48 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by prozacboy666 View Post
Use SQL. Here is how I would do it.
When a new score comes in do a select on the database for the minimum score to get into the top20.
PHP Code:
SELECT MIN(scoreFROM myTable
If new score > min, insert new score into the database and delete the min score.
The only thing is you would have to do two queries to delete the min score from the database something like
PHP Code:
minId SELECT id FROM myTable WHERE score = (SELECT min(scoreFROM myTable)
DELETE FROM top20 WHERE id minId 
Then all you have to do is selects on that table if you are looking for the top20
PHP Code:
SELECT FROM top20 ORDER BY score DESC 
You probably could get the ID and delete it from the database all in one query but this should be fast enough.
You'd need three queries.
1,) Find the minimum score
2,) Add the score
3,) Delete old score


I guess it's what you want to store.
__________________
Reply With Quote
  #3  
Old 12-12-2014, 05:13 PM
prozacboy666 prozacboy666 is offline
Registered User
Join Date: Mar 2002
Posts: 130
prozacboy666 will become famous soon enough
Quote:
Originally Posted by xAndrewx View Post
You'd need three queries.
1,) Find the minimum score
2,) Add the score
3,) Delete old score


I guess it's what you want to store.
I just find it easier because when you want to display the top20 scores, in SQL is does all the work for you and faster than getting all the results and then do some type of sorting function.

Did you use another solution? I am curious on how you did it.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.