Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-30-2005, 04:10 PM "rank" system
SoD
Average Talker

Posts: 21
Trades: 0
Well, im coding an advertising scheme type web page at the moment. What I need to do is figure out a way to show people how ranked they are in order of the amount of clicks they have got. For example:

Bob has been clicked 5 times
Jim has been clicked 2 times
Lisa has been clicked 2 times
John has been clicked 10 times

The amount of clicks is stored in an integer field name m_clicks.

Now, when Bob logs in, he has the second most clicks so itll say "You are ranked 2 out of 4."

When Jim logs in, he is tied with Lisa so we'll fix that by doing it alphabetically. It will say "You are ranked 3 out of 4."

When Lisa logs in, she will see "You are ranked 4 out of 4."

And when John logs in he will see "You are ranked 1 out of 4."


At the moment I got it working via checking every row and ordering them in an array. But if my site gets bigger, I dont want to do that with 3000 rows, for example. That wouldnt be nice to do every time someone logs in. Im SURE there is an easier way I just cant place my finger on it! Does anyone have any ideas?

Thanks
SoD

PS: I did a search for this but I got some rubbish about cars or something, it didnt help anyway.
SoD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-30-2005, 04:45 PM
Marvin Le Rouge's Avatar
Skilled Talker

Posts: 52
Trades: 0
Hi,

Proposition :
1) You get the logger id and m_clicks
2) You do a request asking how many people have m_clicks > (your logger m_clicks)

NB : With this system, you can have ex aequo (what seems just fair to me)
Marvin Le Rouge is offline
Reply With Quote
View Public Profile
 
Old 05-30-2005, 08:05 PM
SoD
Average Talker

Posts: 21
Trades: 0
Well, that works okay for the main part. But, What happens is:

For Jims rank, he gets #3 and for Lisa's rank, she gets #3 aswell, because they both have 2 people with more clicks than them... And If I do >= instead of > then they both turn out as #4

That is my main problem reallly, getting it to order them even if theres more than one person with the same amount of clicks.


Thanks for the help,
Sod
SoD is offline
Reply With Quote
View Public Profile
 
Old 05-31-2005, 02:23 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
what should they be ordered by?

why is lisa 4 and jim 3 and not the other way around?
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-31-2005, 02:30 AM
Marvin Le Rouge's Avatar
Skilled Talker

Posts: 52
Trades: 0
It is absolutely fair that they are both rank 3 if they are 2 people who have more clicks. As they have the same clicks count, you can't order them, and you shouldn't.

Alice 8 clicks
Bob 7 clicks
Jim 5 clicks
Lisa 5 clicks
Tom 4 clicks

should give

Alice rank 1
Bob rank 2
Jim rank 3
Lisa rank 3
Tom rank 5
Marvin Le Rouge is offline
Reply With Quote
View Public Profile
 
Old 05-31-2005, 02:37 AM
OmuCuSucu's Avatar
Vi Veri Veniversum Vivus

Posts: 1,168
Name: Dragos-Valentin
Location: Cluj-Napoca, RO
Trades: 0
i was thinking that you could prolly order them by time also ... the one to reach a certain number of licks first will be first in case someone else has the same amount of clicks.

if you onlyu want to order by number ... that they are both the same rank fair and square ...

if you still need to have no more than one person per rank ... think of what else is of interrest to you? you could order the ones with the same rak by time, name, even length of name as an example...
__________________
.
» Please remember to add to my Talkupation if you enjoyed my post. Thank you :)
.
OmuCuSucu is offline
Reply With Quote
View Public Profile
 
Old 05-31-2005, 04:06 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
He wants to sort them alphabetically - that's already been stated. Why not combine this with your query, something like:

PHP Code:

$uid 
//userid of person you want to rank
$uname //username of this person
$nclicks //no of clicks for this person

$result mysql_query("SELECT COUNT(*) AS num FROM users WHERE numclicks > $nclicks OR (numclicks = $nclicks AND username < '$uname')");

$num mysql_result($result,0,'num');

$rank $num +1
(That SQL is not tested, I just thought it up so the syntax might not be perfect.)
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 05-31-2005, 10:09 AM
SoD
Average Talker

Posts: 21
Trades: 0
0beron, because I didnt even know you could do that in sql query But thanks, ill test it and play around with it if it doesnt work.

OmuCuSucu, im not being sexist if thats what you mean, its alphabetical.

Marvin Le Rouge, I see your point, but im going to try this for the moment and if it turns out to be bad then ill follow your idea. Nothing is gained from ranks, you dont get more money or anything, its just a sort of "healthy competition".
SoD is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to "rank" system
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.75059 seconds with 12 queries