TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-29-2008, 10:37 AM   #1 (permalink)
The Contributor
 
oMIKEo's Avatar
 
Join Date: Jan 2008
Location: Leeds
Posts: 52
Thanks: 7
oMIKEo is on a distinguished road
Default Calculate user ranking

Hi,

I'm trying to work out how to rank a user based on their progress compared to other users.

Here is a simplified example of the structure:

Users
- id

Log
- id
- user_id
- book_id

Books
- id

A user can have multiple number of logs but duplications of the same book shouldn't be counted.

To calculate a book completion percentage i have

$percentage = round(($total_books / 100) * $total_number_of_unique_logs, 2)

but how would i calculate their progress compared to the percentage of other users?

Any help would be great.
Thanks, Mike
Send a message via MSN to oMIKEo
oMIKEo is offline  
Reply With Quote
Old 02-29-2008, 01:23 PM   #2 (permalink)
The Wanderer
 
serversphere's Avatar
 
Join Date: Dec 2006
Location: USA
Posts: 21
Thanks: 0
serversphere is on a distinguished road
Default

Sounds like a job for a relational database (like MySQL). Is your data stored in a database?
Send a message via AIM to serversphere
serversphere is offline  
Reply With Quote
Old 02-29-2008, 02:30 PM   #3 (permalink)
The Contributor
 
oMIKEo's Avatar
 
Join Date: Jan 2008
Location: Leeds
Posts: 52
Thanks: 7
oMIKEo is on a distinguished road
Default

Yeah all the info is stored in a mysql database, its just the process of using that information to get the desired results out that i need help with.
Send a message via MSN to oMIKEo
oMIKEo is offline  
Reply With Quote
Old 02-29-2008, 03:18 PM   #4 (permalink)
The Wanderer
 
serversphere's Avatar
 
Join Date: Dec 2006
Location: USA
Posts: 21
Thanks: 0
serversphere is on a distinguished road
Default

I would let mysql do the work for me. But first, I would get my relational data in the database named correctly. Make it like below, so that book_id in your log table relates to book_id in books table, same with user_id... nit picky observation of mine. ;)

Code:
Users
- user_id

Log
- log_id
- user_id
- book_id

Books
- book_id
Now let mysql do the work for you using a query similar to this:
Code:
SELECT user_id,
(COUNT(book_id) FROM books) AS total_books,
(total_books/100)*COUNT(*) AS book_completion_pctg
FROM log
GROUP BY user_id
ORDER BY book_completion_pctg DESC
I haven't tested this, or thought it through much but hopefully that might get you on the right track.
Send a message via AIM to serversphere
serversphere is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:58 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design