Jump to content

Ranks


Kingy

Recommended Posts

I have some stats for an irc server, which are stored in a mysql database.

 

Table looks like:

User | Lines | Characters

 

When a user types - `mystats, it retrieves his information from the mysql database alll good

 

It will then display - *user* you have written X lines and X characters at an average of X.XX characters per line.

 

That works perfectly fine. What i would also like it to do is say Your rank is: X

 

but i have no idea where to start? hints or tips anyone

Link to comment
https://forums.phpfreaks.com/topic/86406-ranks/
Share on other sites

ordering by lines written

 

yes it stores and yes it works, when someone types a message in irc, the php bot will pick it up find the user who wrote it and add 1 to there line count.

 

Pretty simple and it works, i have made a top 10 ranking which works perfectly well, but i would just like it to display the one rank for the person

Link to comment
https://forums.phpfreaks.com/topic/86406-ranks/#findComment-441529
Share on other sites

Think this might work.  Barand will be of more help as he is scary good at SQL...

 

SELECT COUNT(id) AS rank
FROM (
	SELECT (characters / lines) AS avg_chars
	FROM table_name
)
WHERE avg_chars > (
SELECT (characters / lines)
FROM table_name
WHERE username = 'user'
)

 

May be thrown off by ties.

Link to comment
https://forums.phpfreaks.com/topic/86406-ranks/#findComment-441530
Share on other sites

well u got a top 10 rank u are pretty much there just use a loop to find the user in the listing whilst u increamment a var that will give them there position (just remember before you show them their ranks do $i+1 or else it will show them one under than what they actually are)

Link to comment
https://forums.phpfreaks.com/topic/86406-ranks/#findComment-441533
Share on other sites

yeah ok well for the top 10 ive got

 

$rank = 1;

 

while ... {

$rank $user($lines)

$rank++;

}

 

so that works perfectly well

 

but when trying to do this for individual rank, would i have to make a completely different sql query, because right now i am just going select * from stats where user=$user which will only give me the info for that person not everyone else..

Link to comment
https://forums.phpfreaks.com/topic/86406-ranks/#findComment-441539
Share on other sites

ok im trying but really getting nowhere :S

 

$query = "SELECT count(*) as rank from (select * from stats where written > (select written from stats where user='Kingy') order by written desc)";

 

$result = mysql_query($query) or die(mysql_error());

 

that code gives the error - Every derived table must have its own alias

 

also how would i display the above??

Link to comment
https://forums.phpfreaks.com/topic/86406-ranks/#findComment-441631
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.