Jump to content


Rank System


4 replies to this topic

#1 BlazeForc3

    Young Padawan

  • Members
  • Pip
  • 62 posts
  • Location:Australia

Posted 10 November 2005 - 02:14 AM

Hey ive got a member database each member has a ratio and i want them to each have a rank according to there ratio..

I thought if i query the database and order the results by ratio then there rank would be there row number..

But i dont know how to get a specific users row number?

Edited by BlazeForc3, 10 November 2005 - 07:31 AM.


#2 BlazeForc3

    Young Padawan

  • Members
  • Pip
  • 62 posts
  • Location:Australia

Posted 11 November 2005 - 11:59 PM

Sorry for the double post but maybe i wasnt clear about what i want to do... i want to query my database for a list of all members ordered by there ratio and then get the position of a certain member?

#3 Stu

    Retired P2L Staff

  • Publishing Betazoids
  • PipPipPipPip
  • 1,761 posts
  • Gender:Male

Posted 12 November 2005 - 05:50 AM

well to start with do the query on the database which would be something like

$result = mysql_query("SELECT * FROM table ORDER BY ratio");

as for the other part i honestly dont have a clue how to do it through mysql... but here is another possible 'solution' that might work.

<?
//include your database connect part
 
$ranknumber = '0';

//use ASC and DESC to change the sort order of the results
$result = mysql_query("SELECT * FROM table ORDER BY ratio");

echo "<table>";

while($row=mysql_fetch_array($result))
{
$ratio = $row["ratio"];
$ratio = $row["username"];

echo "<tr><td>$ranknumber++</td><td>$ratio</td><td>$username</td></tr>";
}

echo "</table>";
?>

although i have a feeling it wont work because of the count++ bit always being 1 <3 maybe work on that?

anyone have any comments on that? just an idea anyways, since noone else has posted yet. maybe give it a go

#4 shao

    Original P2L Programmer

  • Members
  • Pip
  • 49 posts
  • Gender:Male
  • Location:Canada

Posted 12 November 2005 - 07:58 AM

Stu has the idea, but add counter outside of the while loop (ie $count=1) and in the while loop do the count++. Do a comparison for the specific member (ie if member_id = $row["member"] then echo $count;). That should do it.

so the idea would be:
count=0
while fetch data from db
if member not found yet
count++
if member found
show the rank or position of the member
end while

-- however you can also do an sql query to find the position of the member. I try to get back to you later, gotta go to work, but try the above one.

Shao

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 12 November 2005 - 01:02 PM

Expanding on shao's idea... a for-loop may be easier.
for($x=1; $row=mysql_fetch_array($result); $x++){
  if($row['username'] == $username_to_be_found){
    echo $x.' - '.$r['username'];
    $found = true;
    break;
  }
}

if(!$found)) die('Member not found');






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users