Jump to content

Getting high score place - for game


slyte33

Recommended Posts

I am trying to get what position a player is in for something, for example:

 

Player -

Level: 100 (6th)

Gold: 1,394,289 (109th)

 

 

My players are stored in a table named 'players'; this is where all of their information is kept.

I've seen it before, but Im having a hard time figuring out how to do it.

 

All help is appreciated, thanks :)

Link to comment
https://forums.phpfreaks.com/topic/186173-getting-high-score-place-for-game/
Share on other sites

So you just need to pull it out of the database?

 

SELECT `players_high_score_ranking` FROM `players` WHERE player = 'whatever'

?

players_high_score_ranking probably isnt the field name but you get the idea..

 

Not exactly. I want to get what place a player is in, like if the results are:

 

Player A - level 100

Player B - level 95

You - level 92

Player C - level 76

 

Then display:

 

Level: 92 (3rd place)

This should give you what you want

 

<?php
$your_cash = "players_cash_value";
$others_cash = "dbtablnameforcash";
$rankresult = mysql_query("SELECT * FROM `players` WHERE `".$others_cash."` > ".$your_cash."");
$rankresult2 = mysql_num_rows($rankresult);
$your_cash = $rankresult2 + 1;
echo "Your ranked number ".$your_cash."!";
?>

This is what I use for my rankings:

 

<?php
$result = mysql_query("SELECT * FROM users ORDER BY score desc") 
$i=1;

	while($row = mysql_fetch_array($result)) 
{
	echo "<tr><td>";
	echo $i;
	echo "</td><td>"; 
	echo $row['player_name'];
	echo "</td><td>"; 
	echo number_format($row['score']);
	$i++;
} 

?>                           

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.