Page 1 of 1
Rank page to a php game [solved]
Posted: Fri Sep 09, 2011 11:29 am
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
Re: Rank page to a php game
Posted: Fri Sep 09, 2011 12:03 pm
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...
Regards,
begood
Re: Rank page to a php game
Posted: Fri Sep 09, 2011 1:25 pm
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";
}
?>
Re: Rank page to a php game
Posted: Fri Sep 09, 2011 2:12 pm
by begood
Hi Chris,
Thanks a lot for the help.
Why do you say my code is disorganized? :s
Re: Rank page to a php game [solved]
Posted: Fri Sep 09, 2011 3:44 pm
by Jackolantern
I never knew we could do [ code=php] and make it highlight PHP code!! That is awesome!
Re: Rank page to a php game [solved]
Posted: Fri Sep 09, 2011 4:08 pm
by begood
Ahahah :')
Re: Rank page to a php game [solved]
Posted: Fri Sep 09, 2011 4:34 pm
by Chris
Jackolantern wrote:
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 '}'.
Re: Rank page to a php game [solved]
Posted: Fri Sep 09, 2011 4:37 pm
by Jackolantern
Chris wrote:Jackolantern wrote:
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.
Re: Rank page to a php game [solved]
Posted: Fri Sep 09, 2011 4:47 pm
by hallsofvallhalla
I keep telling people Chris is a Demi-God but no one believes me....

Re: Rank page to a php game [solved]
Posted: Fri Sep 09, 2011 6:08 pm
by begood
You bet he's!! xD