Rank page to a php game [solved]

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
begood
Posts: 13
Joined: Fri Sep 09, 2011 11:23 am

Rank page to a php game [solved]

Post by begood »

Hey everyone,
I need someone to help me creating a ranking page to my game.

I already try to make it but my ranking page just show one user... =/

Here is my actual "classificacao.php" (rank page):

Code: Select all

<?php include "config.php";
session_start();
?>

<link rel="stylesheet" href="iframe.css" type="text/css" media="screen" title="no title" charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 

<stitle><b><center>Classificação</center></b></stitle><br/>

<?php
$query = "SELECT * FROM utilizadores";

$result = mysql_query($query);

$num=mysql_numrows($result);

$i=0;

while ($i < $num) {

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

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

$i++;

}

echo "<TABLE WIDTH='100%' CELLPADDING='4' CELLSPACING='0'>";
echo "	<COL WIDTH=128*>";
echo "	<COL WIDTH=128*>";
echo "<TR VALIGN=TOP>";
echo "		<TD WIDTH=50% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "	<center>Nome</center>";
echo "</TD>";
echo "	<TD width=50% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "		<center>Dinheiro</center>";
echo "	</TD>";
echo "</TR>";
echo "<TR VALIGN=TOP>";
echo "	<TD WIDTH=50% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "		<center><font family='sans-serif' size='2'>" . $utilizador . "</font></center>";
echo "</TD>";
echo "<TD WIDTH=50% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "	<center><font family='sans-serif' size='2'>" . $dinheiro . "€</font></center>";
echo "	</TD>";
echo "</TR>";
echo "</TABLE>";

?>
If someone could tell me what's wrong with that code or the code to use I'll appreciate a lot!!

Regards,
begood

P.S.: I'm portuguese so, sorry for my bad english. :b
Last edited by begood on Fri Sep 09, 2011 2:30 pm, edited 1 time in total.
Image
User avatar
begood
Posts: 13
Joined: Fri Sep 09, 2011 11:23 am

Re: Rank page to a php game

Post by begood »

Hey guys,
I solved my biggest problem... Now allready appear all the results from database.

My problem now is that:

Instead of:

# Name Money
1 Teste 5000
2 Teste2 5000
3 Teste3 5000

Appears:

# Name Money
1 Teste 5000
# Name Money
2 Teste2 5000
# Name Money
3 Teste3 5000


Here is my code:

Code: Select all

<?php include "config.php";
session_start();
?>

<link rel="stylesheet" href="iframe.css" type="text/css" media="screen" title="no title" charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 

<stitle><b><center>Classificação</center></b></stitle><br/>

<?php
$rowsPerPage = 50;
$_GET['pageNum'] = empty($_GET['pageNum']) === false ? (int)($_GET['pageNum']-1) : 0;

// list of the stuff
$query = mysql_query("SELECT * FROM `utilizadores` ORDER BY `dinheiro` ASC LIMIT ". ($rowsPerPage*$_GET['pageNum']) .",$rowsPerPage");
$i = 1;
while( $array = mysql_fetch_assoc($query) )
{
echo "<TABLE WIDTH='100%' CELLPADDING='4' CELLSPACING='0'>";
echo "   <COL WIDTH=128*>";
echo "   <COL WIDTH=128*>";
echo "<TR VALIGN=TOP>";
echo "      <TD WIDTH=5% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "<center>#</center>";
echo "</TD>";
echo "      <TD WIDTH=65% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "   <center>Nome</center>";
echo "</TD>";
echo "   <TD width=30% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "      <center>Dinheiro</center>";
echo "   </TD>";
echo "</TR>";
echo "<TR VALIGN=TOP>";
echo "   <TD WIDTH=5% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "      <center><font family='sans-serif' size='2'>";
echo (($rowsPerPage*$_GET['pageNum'])+$i);
echo "</font></center>";
echo "</TD>";
echo "<TD WIDTH=65% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "   <center><font family='sans-serif' size='2'>";
echo $array['utilizador'];
echo "</font></center>";
echo "   </TD>";
echo "<TD WIDTH=30% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "   <center><font family='sans-serif' size='2'>";
echo $array['dinheiro'];
echo "€</font></center>";
echo "   </TD>";
echo "</TR>";
echo "</TABLE>";
    
    $i++;
}

// page link
$query = mysql_query("SELECT * FROM `utilizadores`");
for( $i=1; $i<=(mysql_num_rows($query)/$rowsPerPage); $i++ )
{
    echo "<a href=\"{$_SERVER['PHP_SELF']}?pageNum=$i\">". ( ($_GET['pageNum']+1) == $i ? "<strong>$i</strong>" : $i )."</a> \n";
}
?>
If someone can help me... :x

Regards,
begood
Image
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Rank page to a php game

Post by Chris »

I felt like making your code neater, but didn't know where to start to be honest. This should work however.

Code: Select all

<?php
include 'config.php';
session_start();
?>

<link rel="stylesheet" href="iframe.css" type="text/css" media="screen" title="no title" charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 

<stitle><b><center>Classificação</center></b></stitle><br/>

<?php
$rowsPerPage = 50;
$_GET['pageNum'] = empty($_GET['pageNum']) === false ? (int)($_GET['pageNum']-1) : 0;

// list of the stuff
$query = mysql_query("SELECT * FROM `utilizadores` ORDER BY `dinheiro` ASC LIMIT ". ($rowsPerPage*$_GET['pageNum']) .",$rowsPerPage");
$i = 1;
echo "<TABLE WIDTH='100%' CELLPADDING='4' CELLSPACING='0'>";
echo "   <COL WIDTH=128*>";
echo "   <COL WIDTH=128*>";
echo "<TR VALIGN=TOP>";
echo "      <TD WIDTH=5% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "<center>#</center>";
echo "</TD>";
echo "      <TD WIDTH=65% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "   <center>Nome</center>";
echo "</TD>";
echo "   <TD width=30% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "      <center>Dinheiro</center>";
echo "   </TD>";
echo "</TR>";

while( $array = mysql_fetch_assoc($query) )
{
echo "<TR VALIGN=TOP>";
echo "   <TD WIDTH=5% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "      <center><font family='sans-serif' size='2'>";
echo (($rowsPerPage*$_GET['pageNum'])+$i);
echo "</font></center>";
echo "</TD>";
echo "<TD WIDTH=65% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "   <center><font family='sans-serif' size='2'>";
echo $array['utilizador'];
echo "</font></center>";
echo "   </TD>";
echo "<TD WIDTH=30% STYLE='border: 1px solid #cccccc; padding: 1px'>";
echo "   <center><font family='sans-serif' size='2'>";
echo $array['dinheiro'];
echo "€</font></center>";
echo "   </TD>";
echo "</TR>";
    $i++;
}
echo "</TABLE>";
// page link
$query = mysql_query("SELECT * FROM `utilizadores`");
for( $i=1; $i<=(mysql_num_rows($query)/$rowsPerPage); $i++ )
{
    echo "<a href=\"{$_SERVER['PHP_SELF']}?pageNum=$i\">". ( ($_GET['pageNum']+1) == $i ? "<strong>$i</strong>" : $i )."</a> \n";
}
?>
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
begood
Posts: 13
Joined: Fri Sep 09, 2011 11:23 am

Re: Rank page to a php game

Post by begood »

Hi Chris,

Thanks a lot for the help.

Why do you say my code is disorganized? :s
Image
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Rank page to a php game [solved]

Post by Jackolantern »

:shock: :shock:

I never knew we could do [ code=php] and make it highlight PHP code!! That is awesome!
The indelible lord of tl;dr
User avatar
begood
Posts: 13
Joined: Fri Sep 09, 2011 11:23 am

Re: Rank page to a php game [solved]

Post by begood »

Ahahah :')
Image
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Rank page to a php game [solved]

Post by Chris »

Jackolantern wrote::shock: :shock:

I never knew we could do [ code=php] and make it highlight PHP code!! That is awesome!
I've been doing that for years.
begood wrote:Hi Chris,

Thanks a lot for the help.

Why do you say my code is disorganized? :s
Don't want to offend you or anything, if you can look at that and can find your way about it alright that's fine. It's just when pasting code for other people to help you with, it's better to try keep things the way they should be, like we're now in 2011 and no longer use HTML but xHTML, none of our HTML is written in uppercase.
The next tip would be, every time you make a function, loop, if, class, interfaced.. basically anything that needs a curly bracket, '{' to open and close it. It's best to indent the code within it.

Many people write their code like this:

Code: Select all

if( $condition == true ) {
    // indent the code
    echo "Hello world";
}
 
I myself find even this a bit messy and like to turn it into:

Code: Select all

if( $condition == true )
{
    // indent the code
    echo "Hello world";
} 
It's all down to personal preference, but this saves hours and hours of debugging time if you happen to have forgotten a '}'.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Rank page to a php game [solved]

Post by Jackolantern »

Chris wrote:
Jackolantern wrote::shock: :shock:

I never knew we could do [ code=php] and make it highlight PHP code!! That is awesome!
I've been doing that for years.
Wow, no idea how I never noticed that lol.
The indelible lord of tl;dr
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Rank page to a php game [solved]

Post by hallsofvallhalla »

I keep telling people Chris is a Demi-God but no one believes me....:)
User avatar
begood
Posts: 13
Joined: Fri Sep 09, 2011 11:23 am

Re: Rank page to a php game [solved]

Post by begood »

You bet he's!! xD
Image
Post Reply

Return to “General Development”