Page 1 of 1

[BROWSER MMORPG] Add rank page

Posted: Sat Apr 02, 2011 7:59 am
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!!

Re: [BROWSER MMORPG] Add rank page

Posted: Sat Apr 09, 2011 1:59 pm
by hallsofvallhalla
nice!

Re: [BROWSER MMORPG] Add rank page

Posted: Thu Apr 21, 2011 8:29 am
by vitinho444
thanks :)

Re: [BROWSER MMORPG] Add rank page

Posted: Tue Jul 19, 2011 10:10 pm
by Kevin1230
Wow it's awesome!

Re: [BROWSER MMORPG] Add rank page

Posted: Wed Jul 20, 2011 1:43 am
by Nexus
Your tutorials are great! Looking forward to some more! :)

Re: [BROWSER MMORPG] Add rank page

Posted: Wed Jul 20, 2011 11:49 am
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.

Re: [BROWSER MMORPG] Add rank page

Posted: Thu Jul 28, 2011 1:00 am
by dust1031
Thank's man!!!! I added it, and it works great

Re: [BROWSER MMORPG] Add rank page

Posted: Thu Jul 28, 2011 3:18 am
by SpiritWebb
Great job, very nice addition!!