WarDeities Posted February 7, 2008 Share Posted February 7, 2008 I need help making a ranking system....if you have ever played an onling mmorpg you have seen them...like runescape.com I have been programing in php for just over a year and still don't have any clue how to do this... This is my rank.php page <?php $player=$_SESSION['player']; $topplayers="SELECT * from *** where playername='$player'"; $topplayers2=mysql_query($topplayers) or die("Could not get topplayers"); $topplayers3=mysql_fetch_array($topplayers2); $start=$_GET['start']; $start=strip_tags($start); if(!$start) { $start=0; } $end=$start+25; $order="SELECT * from *** where validated='Yes'"; $order2=mysql_query($order); $d=0; $f=0; $g=1; $rank=1; print "<center><table class='maintable'>"; print "<tr class='headline'><td>"; print "<center>Players by Rank</center>"; print "</td></tr></table></center><br>"; print "<table class='maintable'><tr class='headline'>"; print "<td><center>Rank</td><td><center>Player</td><td><center>Status</td><td><center>Race</td><td><center>Deity</td></tr>"; $topplayers="SELECT * from *** where validated='Yes' order by skillpts DESC Limit $start, 25"; $topplayers2=mysql_query($topplayers) or die("Could not query players"); $toprank="SELECT * from rank order by rank ASC Limit $start, 25"; $toprank2=mysql_query($toprank) or die("Could not query ranks"); while(($topplayer3=mysql_fetch_array($topplayers2)) and ($toprank3=mysql_fetch_array($toprank2))) { $topplayer3[playername]=strip_tags($topplayer3[playername]); $toprank3[rank]=strip_tags($toprank3[rank]); if ($topplayers3[iD]==$topplayer3[iD]) { print "<tr class='mainrow'><td><b><center>$toprank3[rank]</td><td><b><center><a href='stats.php?ID=$topplayer3[iD]'>$topplayer3[playername]</a></td><td><b><center>$topplayer3[status]</td><td><b><center>$topplayer3[race]</td><td><b><center>$topplayer3[deity]</td></tr>"; } else { print "<tr class='mainrow'><td><center>$toprank3[rank]</td><td><center><a href='stats.php?ID=$topplayer3[iD]'>$topplayer3[playername]</a></td><td><center>$topplayer3[status]</td><td><center>$topplayer3[race]</td><td><center>$topplayer3[deity]</td></tr>"; } } print "</table>"; print "<br><center>Page: "; while($order3=mysql_fetch_array($order2)) { if($f%25==0) { print "<A href='rank.php?start=$d'>$g</a> "; $g++; } $d=$d+1; $f++; } print "<br><br><A href='home.php'>Go Home</a>."; ?> The output looks like this Located here http://www.wardeities.com/rank.php I just don't know how to update the database to go to the table and put playername TMAROTI rank =1, ihavenopants rank =2...and so on for every player in the game I have played thousands of online games where they have a cron file run every 1, 15, 30, or 60 minutes to update the database ...but i am so clueless on how to do this with mutiple users.. thanks for looking!!! Quote Link to comment Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 how do you want us to help you?...... any ways I don't think you need update. maybe you only need simple select... and we don't know where to start looking for the prob... Quote Link to comment Share on other sites More sharing options...
WarDeities Posted February 7, 2008 Author Share Posted February 7, 2008 I just don't know how to update the database so the player with the most exp is rank 1, then the player with the second highest exp is rank 2, and so on... I am completly unclear on how to write the program that would do this... ??? ??? ??? uhh...I have seen it on thousands of games.....here is the table playername rank experience gold deity....and about 100 other things are are irrevelent to this question. Does anyone know how to update database buy pulling everyones experience in order and then entering where each player name is what their rank is..... I hope I am explaining this the right way... Quote Link to comment Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 IF THAT IS THE ONLY THING YOU WANT you dont need updat you need select and joins...maybe? select sum(field)as field1, field2 from member group by field1 order by field1 this query should give you a highest to lowest ranking Quote Link to comment Share on other sites More sharing options...
WarDeities Posted February 7, 2008 Author Share Posted February 7, 2008 ok...but then how so put that info back in the database so they can view it from other pages...I am trying to make it so they can see their experience rank, offensive army rank, defensive army rank, and so on...so I see I need to be able to put this info back in the database so they can go to home.php and pull from the table their $playername[exprank], $playername[offarmyrank]....that way I can put this info on many pages now just the rank.php page...... Quote Link to comment Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 just do that in every page.. note: UPDATING db in that case will be more complected select is you best bet.. Quote Link to comment Share on other sites More sharing options...
WarDeities Posted February 7, 2008 Author Share Posted February 7, 2008 so how is that going to give Zero that he is rank 15??? I don't need to get the players that are rank 1-14 or 16-200...i just want to get it for him that he is rank 15! This is what I use on almost every page to get the player their stats! $player=$_SESSION['player']; $player="SELECT * from users where playername='$player'"; $player2=mysql_query($player) or die("Could not get player"); $player3=mysql_fetch_array($player2); $experience=$player3[experience] $rank=$player3[rank] I need to figure out if $player='Zero' than $rank=15 I appologize if I am explaining this incorrectly. I mean I could do it with one player like this $topplayers="SELECT * from users where playername='$player[playername]'"; $topplayers2=mysql_query($topplayers) or die("Could not get topplayers"); $topplayers3=mysql_fetch_array($topplayers2); $numrows="SELECT * from users where skillpts>='$topplayers3[experience]'"; $numrows2=mysql_query($numrows) or die("Could not grab rows"); $numrows3=mysql_num_rows($numrows2); $numrows3=$numrows3-1; $getrank="SELECT * from users where validated='Yes' order by skillpts desc limit $numrows3,1"; $getrank2=mysql_query($getrank) or die("Could not fetch ranks"); $toprank="SELECT * from rank order by rank ASC Limit $numrows3,1"; $toprank2=mysql_query($toprank) or die("Could not query ranks"); print "<b>Rank: </b>"; while(($getrank3=mysql_fetch_array($getrank2)) and ($toprank3=mysql_fetch_array($toprank2))) {print "$toprank3[rank]<br>";} Then I could do this $update="update users set rank=$toprank3[rank] playername='$player'"; mysql_query($update) or die("Did Not Update"); This would put in the database (for The current player only) their rank....is there a way to do this for all players in the database at one time??? The above case would make Zero's Rank 15.... Quote Link to comment Share on other sites More sharing options...
WarDeities Posted February 7, 2008 Author Share Posted February 7, 2008 here are the two tables if it helps... Table 1 (users) playername experience rank Table 2 (rank) ID rank Quote Link to comment Share on other sites More sharing options...
teng84 Posted February 7, 2008 Share Posted February 7, 2008 select sum(kill)as ranks,experience from user group by userid order by ranks limit 15 now if there id is not on that list then 0 no ranking! is that what you mean? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.