MyBB Community Forums

Full Version: Increment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

I want to display a table with data from the database which will show for example User and Rank.

I use 'db->fetch_array' to display the username but for the rank I don't know how to make it to increase with every user in the table, example:

Username | Rank
usr | 1
usr2 | 2
usr3 | 3

etc.

Any idea?
$query = $db->query("SELECT `username`, `rank` FROM `".TABLE_PREFIX."users`");
while($row = $db->fetch_array($query)) {
   echo ($row['username'].' | '.$row['rank']);
}

Not tested, so you may have to modify it.
I don't think you understood me but anyway I found a way to do it.
(2011-11-25, 01:28 AM)pyridine Wrote: [ -> ]
$query = $db->query("SELECT `username`, `rank` FROM `".TABLE_PREFIX."users`");
while($row = $db->fetch_array($query)) {
   echo ($row['username'].' | '.$row['rank']);
}

Not tested, so you may have to modify it.

Better way to do that would be
$query = $db->simple_select("users","username,rank");
while($row = $db->fetch_array($query)) {
   echo ($row['username'].' | '.$row['rank']);
}
^^
Why would you need "rank" anyways... you're just talking about the order they're in the db... so just use their uid!
I figured out how to do it. Thanks!