RoninStretch Posted April 27, 2007 Share Posted April 27, 2007 hey guys. Im noob at php+mysql so hope someone won't mind helping with a little theory. I have a database of users, each with a 'points' field.. What i want is to have is a ranking page displaying the top ten users. (the ten users with the most points). So i know there must be a better way then calling all the data and messing with it in the script. I don't know if the way to go is to re-order the rows using some sort of sorting algorithm and display the top ten.. OR to have the server compile a list of top points users once a day or something and when the user goes to the topten page it just retrieves that info.. Any help and code snippets you can give will be a great aid to me.. Thanks! - Stretch. Link to comment https://forums.phpfreaks.com/topic/48887-a-bit-of-database-theory/ Share on other sites More sharing options...
genericnumber1 Posted April 27, 2007 Share Posted April 27, 2007 uhhh your query would be SELECT * FROM users ORDER BY points DESC LIMIT 10 you might do better with an index on points, but that's just my 2 cents Link to comment https://forums.phpfreaks.com/topic/48887-a-bit-of-database-theory/#findComment-239607 Share on other sites More sharing options...
RoninStretch Posted April 27, 2007 Author Share Posted April 27, 2007 Right so it's just that simple? Like i said.. I'm noob.. Dont know what index's are. Link to comment https://forums.phpfreaks.com/topic/48887-a-bit-of-database-theory/#findComment-239610 Share on other sites More sharing options...
genericnumber1 Posted April 27, 2007 Share Posted April 27, 2007 yup, it's just that simple. indexes are just ways of "indexing" (bet you didn't see that coming) the values of a column so that they are retrieved more quickly... SELECT statements occur much faster when they use that column but insert queries take longer and it takes up more room on the disk. If you're not going to be selecting the column a lot or if you're going to be changing the column a lot then an index may not be best... (Unique) Indexes are good for things like usernames, etc. Link to comment https://forums.phpfreaks.com/topic/48887-a-bit-of-database-theory/#findComment-239613 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.