Jump to content


Photo

Ranking System


  • Please log in to reply
1 reply to this topic

#1 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 16 October 2006 - 11:33 PM

what would be a good way to start out a ranking system?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 17 October 2006 - 10:25 PM

Supposing you have a table "item" containing items to be rated

item
--------
item_id
item_name

Createa second table to store your users rating scores

rating
-----------
id
item_id          // id of the item being rated
score
user_id          // optional - use if users must login and can only vote once

To get the top 10 rankings

SELECT i.item_name, AVG(r.score) as avscore
FROM item i
INNER JOIN rating r ON i.item_id = r.item_id
ORDER BY avscore DESC
LIMIT 10
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users