Jump to content

Recommended Posts

I have a system that i'm working on that lats say has 1000 members now.

Each member has his own display page and own rating points.

 

What i want to do (and dont know how :)) is to show on each of the members page his rank out of all the 1000 members.

Like:

 

V-Tech Ranked 317 of 1000 members

 

 

Of course all the info is set on a SQL db.

 

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/
Share on other sites

what is your table like in the db ?

I have the "rating" field that will be changed all the time depending on what the members will do and by that field i want it to be sorted.

 

adam291086:

It's not sorted out, each member has his rating points and i want it to be sorted and shown by that.

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439681
Share on other sites

well in you sql do something like

 

SELECT * FROM Foo

ORDER BY Rank DESC

 

Thank will give you all the ranking starting with the highest rank

 

I know how to creat a page that will show me all the members and sort it, but what i'm trying to do is find what is a rating of a specific member out of everyone and show it on a page without the rest of the members.

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439683
Share on other sites

Well how are you getting that specific member? like burnside and i said, why not count the number of records and echo it out along with their rank

 

Well if the ranking is stored in the database then all you will need to do is count how many records you have in your database, mysql_count_rows i think, then echo that result out with there rank

 

echo $rank;

echo "out of";

echo $total records;

 

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439691
Share on other sites

well if the rating is saved in the db why cant you just echo that value out?

The rating is saved but it's like number of points that the member has, and i want to make a code that will how much points the rest of the members has and tell me what is the rank of that member out of everyone.

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439692
Share on other sites

Well how are you getting that specific member? like burnside and i said, why not count the number of records and echo it out along with their rank

 

Well if the ranking is stored in the database then all you will need to do is count how many records you have in your database, mysql_count_rows i think, then echo that result out with there rank

 

echo $rank;

echo "out of";

echo $total records;

 

The rank is not saved in the DB, the rating is saved and the rating is just number of points the member has.

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439694
Share on other sites

well you could try this

 


<?php

//work out the number of members
$query1 = "SELECT * FROM `table_name`"; 
$result1 = mysql_query($query);
$row1 = mysql_count_rows($result1)

//work out the rank
$query = "SELECT * FROM `table_name` ORDER BY `rating` DESC"; 
$result = mysql_query($query);
$ranknumber = 1;

while($row = mysql_fetch_array($result)){		

echo $ranknumber . ". " . $row['username'] . ", with " . $row['rating'] . " points out of" . $row1. "<br>";		

$ranknumber++; 
// increases $ranknumber by 1	
}?>

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439702
Share on other sites

well you could try this

 


<?php

//work out the number of members
$query1 = "SELECT * FROM `table_name`"; 
$result1 = mysql_query($query);
$row1 = mysql_count_rows($result1)

//work out the rank
$query = "SELECT * FROM `table_name` ORDER BY `rating` DESC"; 
$result = mysql_query($query);
$ranknumber = 1;

while($row = mysql_fetch_array($result)){		

echo $ranknumber . ". " . $row['username'] . ", with " . $row['rating'] . " points out of" . $row1. "<br>";		

$ranknumber++; 
// increases $ranknumber by 1	
}?>

 

It's not working... There is an error in the script. And i dont think that this is what i had in mind :)

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439707
Share on other sites

Maybe i'll explain better -

In my DB table i have 3 feilds: ID,USERNAME,POINTS

Now i have 5 members in there:

 

ID USERNAME POINTS

1  Test1        10

2  Test2        56

3  Test3        1

4  Test4        34

5  Test5        15

 

Now i have a page that shows each of the members "profile" and in that page i want it to show me the rank of one member.

If for example i'm viewing Test3 members page i want it to tell me there that he is ranked 5 out of 5 members as he has the lowest points.

 

Maybe it's more clear now.

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439711
Share on other sites

This is what you want

 

<?php

//work out the number of members
$query1 = "SELECT * FROM `table_name`"; 
$result1 = mysql_query($query);
$row1 = mysql_count_rows($result1)

//work out the total number of points

$sum = "SELECT *, SUM(POINTS) FROM table name "; 
$result3 = mysql_query($sum);

//work out the rank
$query = "SELECT * FROM `table_name` ORDER BY `rating` DESC"; 
$result = mysql_query($query);
$ranknumber = 1;

while($row = mysql_fetch_array($result)){		

echo $row['USERNAME']."is ranked".$ranknumber. "out of" . $row1. "members" . "with a point score of". $row['POINTS']."out of a possible".$result3. "<br />"

$ranknumber++; 
// increases $ranknumber by 1	
}?>

 

That will add a rank to the user depening on there point score.

Work out how many members there are and echo that result

works out the total number of points that have been issues

so the echo will look like this

 

adam is ranked 1  out of 5 members with a point score of 10 out of a possible 20

Link to comment
https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439716
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.