marcus Posted February 20, 2007 Share Posted February 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/39339-solved-for-while-problems/ Share on other sites More sharing options...
Balmung-San Posted February 20, 2007 Share Posted February 20, 2007 What's your question? Quote Link to comment https://forums.phpfreaks.com/topic/39339-solved-for-while-problems/#findComment-189712 Share on other sites More sharing options...
marcus Posted February 20, 2007 Author Share Posted February 20, 2007 How can I get it so it shows, 1,2,3,4,5,6,7,8,9,10 instead of 1,1,1,1,1,1,1,1,1,1 Quote Link to comment https://forums.phpfreaks.com/topic/39339-solved-for-while-problems/#findComment-189713 Share on other sites More sharing options...
Balmung-San Posted February 20, 2007 Share Posted February 20, 2007 You don't need the for loop. Outside of the while loop declare $i, then inside the while loop (but after the echo) do $i++; Quote Link to comment https://forums.phpfreaks.com/topic/39339-solved-for-while-problems/#findComment-189716 Share on other sites More sharing options...
marcus Posted February 20, 2007 Author Share Posted February 20, 2007 $i=0; while($row = mysql_fetch_assoc($res)){ $i++; echo "<tr><td align=center>$i</td><td align=center>$row[username]</td><td align=center>$row[royal]</td></tr>\n"; } Worked like a charm, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/39339-solved-for-while-problems/#findComment-189717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.