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
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
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
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
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
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
Share on other sites

OK ill try i..

 

$query = 'select * from user oder by rank desc;

$query =mysql_query($query);

while($row = mysql_fetch_array($query )){

    ++$x;

  if ($row[id] == yourid){

    echo 'rank'.$x;   

    break;

  }

}

 

this will echo the rank of specific user

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.