[BROWSER MMORPG] Add rank page

Post all your tuts or request for tuts here.
Post Reply
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

[BROWSER MMORPG] Add rank page

Post by vitinho444 »

Hey guys, so its time to contribute for the community with a resource for the browser based mmorpg.

so lets start:

what it would do: well, it will be an page where players can check other players (this is awesome in multiplayer mmorpgs), check theire levels and more if you want of course.

Create a new .php file called rank.php

then add this code to it:

Code: Select all

<?php

include_once 'connect.php';

 session_start();

   include_once 'logo.php';

   ?>

     <link href="style.css" rel="stylesheet" type="text/css" />

<?php

if (isset($_SESSION['player']))

{

  $player=$_SESSION['player'];

}

else

{

  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";

  exit;

}

$playerinfo="SELECT * from players where name='$player'";

$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");

$playerinfo3=mysql_fetch_array($playerinfo2);

include_once 'statpanel.php';

?>
this is the basic code to add the logo, the statpanel and fetch the player info.


now we want to display the variables in db: Name and Level

now we add this code in the end:

Code: Select all

<?php

echo "<br>Player Name / Level / Gold /<br>";



$query = "SELECT * FROM players";

$result = mysql_query($query);

$num=mysql_numrows($result);



$i=0;

while ($i < $num) {



$name = mysql_result($result,$i,"name");

$level = mysql_result($result,$i,"level");

$gold = mysql_result($result,$i,"gold");

$i++;



echo "<br>Name: " . $name . " /  Level: " . $level . " /  Gold: " . $gold . "<br>";





}

echo "<br><br><a href='index.php'>Go Back</a><br>";







?>
now lets see the code:

Code: Select all

echo "<br>Player Name / Level / Gold /<br>";
this will display the order of our rank .

Code: Select all

$query = "SELECT * FROM players";

$result = mysql_query($query);

$num=mysql_numrows($result);



$i=0;
this code here will check the number of players, to add to rank page, it will select all the players from the Table.

Code: Select all

while ($i < $num) {



$name = mysql_result($result,$i,"name");

$level = mysql_result($result,$i,"level");


$i++;



echo "<br>Name: " . $name . " /  Level: " . $level . " / <br>";





}
now a simple loop that will display the information of each player by order and at the beginning it will fetch players info

and now the Go Back button:

Code: Select all

echo "<br><br><a href='index.php'>Go Back</a><br>";







?>

well done now you got the rank page!


You can check all the code here: (i added gold to my rank page)

Code: Select all

<?php

include_once 'connect.php';

 session_start();

   include_once 'logo.php';

   ?>

     <link href="style.css" rel="stylesheet" type="text/css" />

<?php

if (isset($_SESSION['player']))

{

  $player=$_SESSION['player'];

}

else

{

  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";

  exit;

}

$playerinfo="SELECT * from players where name='$player'";

$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");

$playerinfo3=mysql_fetch_array($playerinfo2);

include_once 'statpanel.php';

?>



<?php

echo "<br>Player Name / Level / Gold /<br>";



$query = "SELECT * FROM players";

$result = mysql_query($query);

$num=mysql_numrows($result);



$i=0;

while ($i < $num) {



$name = mysql_result($result,$i,"name");

$level = mysql_result($result,$i,"level");

$gold = mysql_result($result,$i,"gold");

$i++;



echo "<br>Name: " . $name . " /  Level: " . $level . " /  Gold: " . $gold . "<br>";





}

echo "<br><br><a href='index.php'>Go Back</a><br>";







?>






To add more things just edit inside the loop this:

$name = mysql_result($result,$i,"name");

$level = mysql_result($result,$i,"level");

$gold = mysql_result($result,$i,"gold");

$youroption = mysql_result($result,$i,"HERE WHAT YOU WANNA SHOW");


remmember that the
"HERE WHAT YOU WANNA SHOW"
part its where you add the "player info" that you wanna show in rank page (ex: email, hpoints, gold etc)

then when you add the variable just add it to the display like this~:

Code: Select all

echo "<br>Name: " . $name . " /  Level: " . $level . " /  Gold: " . $gold . " /  youroption: " . $youroption . "<br>";
And done!
hope it works for you (it worked for me) and i hope you like it.
Of course you can customize your way, and don't forget to credit the only "person" who deserves to be credit: indie-resource.com!!
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: [BROWSER MMORPG] Add rank page

Post by hallsofvallhalla »

nice!
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: [BROWSER MMORPG] Add rank page

Post by vitinho444 »

thanks :)
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
Kevin1230
Posts: 62
Joined: Mon Jul 18, 2011 3:32 pm

Re: [BROWSER MMORPG] Add rank page

Post by Kevin1230 »

Wow it's awesome!
User avatar
Nexus
Posts: 293
Joined: Sat Jun 18, 2011 10:42 pm

Re: [BROWSER MMORPG] Add rank page

Post by Nexus »

Your tutorials are great! Looking forward to some more! :)
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: [BROWSER MMORPG] Add rank page

Post by vitinho444 »

lol im not pro in PHP so i add the things i learn by testing things out XD if i got another i will add here.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
dust1031
Posts: 92
Joined: Fri Jul 22, 2011 3:38 am

Re: [BROWSER MMORPG] Add rank page

Post by dust1031 »

Thank's man!!!! I added it, and it works great
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: [BROWSER MMORPG] Add rank page

Post by SpiritWebb »

Great job, very nice addition!!
Image

Image
Post Reply

Return to “Tutorials”