Jump to content

[SOLVED] For + While Problems


marcus

Recommended Posts

I'm trying to create a high score list while show the correct placement of the user, 1-10.

 

Code:

<?php
$global_check=3;
include('../global.php');
$sql = "SELECT * FROM `characters` ORDER BY `royal` DESC LIMIT 10";
$res = mysql_query($sql) or die(mysql_error());
echo "<center>\n";
echo "<table border=0 cellspacing=3 cellpadding=3 width=400>\n";
echo "<tr><td colspan=3 align=center class=bar><font class=barfont>test</font></td></tr>\n";
echo "<tr><td align=center>#</td><td align=center>Username</td><td align=center>Points</td></tr>\n";
for($i=1;$i<11;$i++){
while($row = mysql_fetch_assoc($res)){
echo "<tr><td align=center>$i</td><td align=center>$row[username]</td><td align=center>$row[royal]</td></tr>\n";
}
}
echo "</table></center>\n";
?>

 

Result:

 

test

# Username Points

1 marcus 175

1 neoisboring 149

1 hxcChaos 74

1 Jen 71

1 Sparts 49

1 SpiritWarrior 23

1 Damon 23

1 Sarah 21

1 Rachykins 17

1 kellykoo 16

Link to comment
https://forums.phpfreaks.com/topic/39339-solved-for-while-problems/
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.