Help With Rankings

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Help With Rankings

Post by MikeD »

Alright, I'm not even sure if this is possible or not.

What I'd like to have a script do is this..

When you view a players profile, it shows you their rank compared to everybody else in every skill.

Such as on the players profile, say the player has the highest speed, and is second best in strength i'd like it show like this.

Speed - Rank 1
Strength - Rank 2

It seems like you'd have to sort a column in the database and echo out the position that they are in. Not exactly sure how to do this, or if possible.

Is there a mysqli function to do this, or am I out of luck?
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Help With Rankings

Post by MikeD »

Oroton wrote:Just add a new column to the same table as where the speed and other skills lets say they are in chapter table
With names strength and speed then make new columns speed_rank and strength_rank and have the values stored there, very easy and possible... And just echo the data like you said
Anything is possible...
Leaves me in the same spot, how do I determine what speed_rank is when the player levels up.
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Help With Rankings

Post by MikeD »

Thanks for the help but that's not what I'm looking for.

What I'm looking for is how to find a players Rank in each skill, compared to every other player.
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: Help With Rankings

Post by Winawer »

Sounds like you're looking for something like

Code: Select all

SELECT COUNT(id)+1 as rank FROM players WHERE skill>$playerSkill
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Help With Rankings

Post by MikeD »

Winawer wrote:Sounds like you're looking for something like

Code: Select all

SELECT COUNT(id)+1 as rank FROM players WHERE skill>$playerSkill
How would I use this and echo the result?

This is what I have, and I get undefined index speed on the echo line.

<?php
$rank="SELECT COUNT(cid)+1 as rank FROM `characters` WHERE `speed`>'$profile3[speed]'";
$rank2=mysqli_query($db,$rank) or die (mysqli_error($db));
$rank3=mysqli_fetch_array($rank2);
echo "Speed: Rank " . $rank3['speed']. "<br>";
?>
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: Help With Rankings

Post by Winawer »

MikeD wrote:
Winawer wrote:Sounds like you're looking for something like

Code: Select all

SELECT COUNT(id)+1 as rank FROM players WHERE skill>$playerSkill
How would I use this and echo the result?

This is what I have, and I get undefined index speed on the echo line.

<?php
$rank="SELECT COUNT(cid)+1 as rank FROM `characters` WHERE `speed`>'$profile3[speed]'";
$rank2=mysqli_query($db,$rank) or die (mysqli_error($db));
$rank3=mysqli_fetch_array($rank2);
echo "Speed: Rank " . $rank3['speed']. "<br>";
?>
Use "rank" with $rank3 (not "speed"):

Code: Select all

<?php
$rank="SELECT COUNT(cid)+1 as rank FROM `characters` WHERE `speed`>'$profile3[speed]'";
$rank2=mysqli_query($db,$rank) or die (mysqli_error($db));
$rank3=mysqli_fetch_array($rank2);
echo  "Speed: Rank " . $rank3['rank']. "<br>";
?>
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Help With Rankings

Post by MikeD »

Winawer wrote:
MikeD wrote:
Winawer wrote:Sounds like you're looking for something like

Code: Select all

SELECT COUNT(id)+1 as rank FROM players WHERE skill>$playerSkill
How would I use this and echo the result?

This is what I have, and I get undefined index speed on the echo line.

<?php
$rank="SELECT COUNT(cid)+1 as rank FROM `characters` WHERE `speed`>'$profile3[speed]'";
$rank2=mysqli_query($db,$rank) or die (mysqli_error($db));
$rank3=mysqli_fetch_array($rank2);
echo "Speed: Rank " . $rank3['speed']. "<br>";
?>
Use "rank" with $rank3 (not "speed"):

Code: Select all

<?php
$rank="SELECT COUNT(cid)+1 as rank FROM `characters` WHERE `speed`>'$profile3[speed]'";
$rank2=mysqli_query($db,$rank) or die (mysqli_error($db));
$rank3=mysqli_fetch_array($rank2);
echo  "Speed: Rank " . $rank3['rank']. "<br>";
?>
Works like a charm, thanks alot! :)
Post Reply

Return to “Advanced Help and Support”