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';
?>
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>";
?>
Code: Select all
echo "<br>Player Name / Level / Gold /<br>";
Code: Select all
$query = "SELECT * FROM players";
$result = mysql_query($query);
$num=mysql_numrows($result);
$i=0;
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>";
}
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
part its where you add the "player info" that you wanna show in rank page (ex: email, hpoints, gold etc)"HERE WHAT YOU WANNA SHOW"
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>";
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!!