Jump to content

Archived

This topic is now archived and is closed to further replies.

CMellor

Number Increment Next To MySQL Querys

Recommended Posts

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]<?php
include("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]<?php
for($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

Share this post


Link to post
Share on other sites
[code]
<?php
for($count = 1; $row = mysql_fetch_array($query); $count++) {
  echo $count.':'.$row['members_display_name'].'<br />';
}
?>
[/code]

Share this post


Link to post
Share on other sites
I would also put a [code=php:0]mysql_free_result($query);[/code] at the end

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.