CMellor Posted July 29, 2006 Share Posted July 29, 2006 Hello, I have a question about PHP and I hope I can get some help.I have a simple bit of code that lists the members on my forum.[code]<?phpinclude("include/dbconnect.php");$query = mysql_query("SELECT * FROM ibf_members") or die(mysql_error());while($row = mysql_fetch_array($query)) { echo $row['members_display_name'] .'<br />';}?>[/code]I am building a ranking page on my site, where they will be listed in order of most points (I have a points hack) and I wanted to list each of them with a number next to it, but not to use their ID because I want to list it from 1-10.[code]<?phpfor($count = 1; $count <= 10; $count++) { echo $count .'<br />';}?>[/code]I know this bit of code creates a 1-10 list and I was trying to use it in the other code I provided to list each DB query as a number. I hope I make sense, I'm not great at talking about coding.Thanks for your time.Chris Quote Link to comment Share on other sites More sharing options...
shoz Posted July 29, 2006 Share Posted July 29, 2006 [code]<?phpfor($count = 1; $row = mysql_fetch_array($query); $count++) { echo $count.':'.$row['members_display_name'].'<br />';}?>[/code] Quote Link to comment Share on other sites More sharing options...
tomfmason Posted July 29, 2006 Share Posted July 29, 2006 I would also put a [code=php:0]mysql_free_result($query);[/code] at the end Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 29, 2006 Share Posted July 29, 2006 It would certainly make sense to SELECT what you need ... for example, to get only the 10 highest point holders ordered in descending order: [code]$query = "SELECT member_name from your_table_name ORDER by points DESC LIMIT 10";[/code] Quote Link to comment Share on other sites More sharing options...
CMellor Posted July 29, 2006 Author Share Posted July 29, 2006 Thank you very much, that is just what I wanted :) Quote Link to comment 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.