Jump to content

Noob Problem..


seany123

Recommended Posts

In this game im making i have a highscores page, now ive done alot of the worked needed but now ive hit something i dont know what to do.

 

all i want is for beneath 'Rank' is for the numbers 1 - 50 Goes down.

 

<?php
include("lib.php");

define("PAGENAME", "Hall Of Fame");
$player = check_user($secret_key, $db);



include("templates/private_header.php");
?><style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
a:link {
color: #FF0000;
}
a:visited {
color: #FF0000;
}
a:hover {
color: #666666;
}
a:active {
color: #FF0000;
}
.style5 {color: #FFFFFF}
-->
</style>
<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr>
    <td align="center" class="style5"><strong>Hall Of Fame </strong></td>
  </tr>
</table>
<table width="660" border="0">
  <tr>
    <td width="90"><div align="center"><a href="levelhof.php">Level</a></div></td>
    <td width="90"><div align="center"><a href="moneyhof.php">Money</a></div></td>
    <td width="90"><div align="center"><a href="bankhof.php">Bank</a></div></td>
    <td width="90"><div align="center"><a href="pointshof.php">Points</a></div></td>
    <td width="90"><div align="center"><a href="strengthhof.php">Strength</a></div></td>
    <td width="90"><div align="center"><a href="defencehof.php">Defence</a></div></td>
    <td width="90"><div align="center"><a href="speedhof.php">Speed</a></div></td>
  </tr>
</table>
<br>
<table width="31%" border="0" align="center">
<tr>
  <th width="33%">Rank  
<th width="33%"><b>Username</b></td>
<th width="33%"><strong>Money</strong>
<th width="34%"><strong>Level</strong></tr>
<?php
//Select all members ordered by level (highest first, members table also doubles as rankings table)
$query = $db->execute("select `id`, `username`, `level`, `money` from `players` order by `level` desc limit 50");

while($member = $query->fetchrow())
{
echo "<tr>\n";
echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";
echo ($member['username'] == $player->username)?"<b>":"";
echo $member['username'];
echo ($member['username'] == $player->username)?"</b>":"";
echo "<td>" . $member['money'] . "</td>\n";
echo "<td>" . $member['level'] . "</td>\n";
echo "</tr>\n";
}
?>
</table>

<div align="left">
  <?php
include("templates/private_footer.php");
?>
</div>

 

can someone please help me out on this one?

Link to comment
https://forums.phpfreaks.com/topic/124684-noob-problem/
Share on other sites

Set a counter and increment it in your loop:

 


$i = 1;
while($member = $query->fetchrow())
{
echo "<tr>\n";
echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";
echo ($member['username'] == $player->username)?"<b>":"";
echo $i.'. '.$member['username'];
echo ($member['username'] == $player->username)?"</b>":"";
echo "<td>" . $member['money'] . "</td>\n";
echo "<td>" . $member['level'] . "</td>\n";
echo "</tr>\n";
$i++;
}

Link to comment
https://forums.phpfreaks.com/topic/124684-noob-problem/#findComment-643986
Share on other sites

$i = 1;

while($member = $query->fetchrow())
{
echo "<tr>\n";
       echo "<td>$i</td>";
echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";
echo ($member['username'] == $player->username)?"<b>":"";
echo $member['username'];
echo ($member['username'] == $player->username)?"</b>":"";
echo "<td>" . $member['money'] . "</td>\n";
echo "<td>" . $member['level'] . "</td>\n";
echo "</tr>\n";
   
      $i++;
}

 

EDIT: Beat to it.

Link to comment
https://forums.phpfreaks.com/topic/124684-noob-problem/#findComment-643989
Share on other sites

only problem with this is because i added a new part to the table, (rank).

 

now the usernames are listed under the rank table and the other have all moved left also.

 

and the $i++; bit is right next to the username.

 

example

 

Rank          Username  Money Level

1username  $5000        10   

 

thats basically how its looking.

 

this is the code im using.

 

<?php
include("lib.php");

define("PAGENAME", "Hall Of Fame");
$player = check_user($secret_key, $db);



include("templates/private_header.php");
?><style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
a:link {
color: #FF0000;
}
a:visited {
color: #FF0000;
}
a:hover {
color: #666666;
}
a:active {
color: #FF0000;
}
.style5 {color: #FFFFFF}
-->
</style>
<table width="650" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">
  <tr>
    <td align="center" class="style5"><strong>Hall Of Fame </strong></td>
  </tr>
</table>
<table width="660" border="0">
  <tr>
    <td width="90"><div align="center"><a href="levelhof.php">Level</a></div></td>
    <td width="90"><div align="center"><a href="moneyhof.php">Money</a></div></td>
    <td width="90"><div align="center"><a href="bankhof.php">Bank</a></div></td>
    <td width="90"><div align="center"><a href="pointshof.php">Points</a></div></td>
    <td width="90"><div align="center"><a href="strengthhof.php">Strength</a></div></td>
    <td width="90"><div align="center"><a href="defencehof.php">Defence</a></div></td>
    <td width="90"><div align="center"><a href="speedhof.php">Speed</a></div></td>
  </tr>
</table>
<br>
<table width="31%" border="0" align="center">
<tr>
  <th width="20%">Rank
  
  <th width="28%"><b>Username</b></td>
<th width="24%"><strong>Money</strong>
<th width="28%"><strong>Level</strong></tr>
<?php
//Select all members ordered by level (highest first, members table also doubles as rankings table)
$query = $db->execute("select `id`, `username`, `level`, `money` from `players` order by `level` desc limit 50");

$i = 1;
while($member = $query->fetchrow())
{
echo "<tr>\n";
echo $i++;
echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";
echo ($member['username'] == $player->username)?"<b>":"";
echo $member['username'];
echo ($member['username'] == $player->username)?"</b>":"";
echo "<td>" . $member['money'] . "</td>\n";
echo "<td>" . $member['level'] . "</td>\n";
echo "</tr>\n";
$i++;
}
?>
</table>

<div align="left">
  <?php
include("templates/private_footer.php");
?>
</div>

Link to comment
https://forums.phpfreaks.com/topic/124684-noob-problem/#findComment-644141
Share on other sites

Why are you echoing $i++? The problem your having now is just an HTML issue.

 

You need to put <td>'s around the $i.

 

while($member = $query->fetchrow())
{
echo "<tr>\n";
echo "<td>$i</td>;
echo "<td><a href=\"profile.php?id=" . $member['username'] . "\">";
echo ($member['username'] == $player->username)?"<b>":"";
echo $member['username'];
echo ($member['username'] == $player->username)?"</b>":"";
echo "<td>" . $member['money'] . "</td>\n";
echo "<td>" . $member['level'] . "</td>\n";
echo "</tr>\n";
$i++;
}

 

Also, you never close any of your <th>'s.

Link to comment
https://forums.phpfreaks.com/topic/124684-noob-problem/#findComment-644427
Share on other sites

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.