Verbat Posted January 15, 2008 Share Posted January 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/ Share on other sites More sharing options...
beansandsausages Posted January 15, 2008 Share Posted January 15, 2008 what is your table like in the db ? Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439676 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439679 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439681 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439682 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439683 Share on other sites More sharing options...
beansandsausages Posted January 15, 2008 Share Posted January 15, 2008 well if the rating is saved in the db why cant you just echo that value out? Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439690 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 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; Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439691 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439692 Share on other sites More sharing options...
beansandsausages Posted January 15, 2008 Share Posted January 15, 2008 this ill leave this one to you adam291086 haha Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439693 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439694 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 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 }?> Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439702 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439707 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 sorry i can see where i have gone wrong. You want to add up the total rating points of all the member and display there ranking and there point out of a possible x amount Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439710 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439711 Share on other sites More sharing options...
beansandsausages Posted January 15, 2008 Share Posted January 15, 2008 like adam said : SELECT * FROM Foo WHERE id_foo = foo ORDER BY Rank DESC will only show that id just echo the id number and that will give him his rank i think not to sure though. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439713 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439716 Share on other sites More sharing options...
beansandsausages Posted January 15, 2008 Share Posted January 15, 2008 @adam like the adam is ranked 1st hahaha Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439721 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 It tells me that there is an error on this like - $query = "SELECT * FROM `table_name` ORDER BY `rating` DESC"; And i changed the details so it will fit my DB Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439730 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 add that to the end of thw sql or die('Query failed. ' . mysql_error()); for example $result = mysql_query($query) or die('Query failed. ' . mysql_error()); tell me what the errors are so i can help Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439731 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 Parse error: syntax error, unexpected T_VARIABLE in c:\wamp\www\fusion\test.php on line 29 That's the error. Any chance you have MSN or something? Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439734 Share on other sites More sharing options...
beansandsausages Posted January 15, 2008 Share Posted January 15, 2008 i think missed a ; out i could be wrong though. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439736 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 i am at work so no msn. HAHA i working really hard What is on line 29. We are not mind readers you have to be specific with errors and line numbers. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439738 Share on other sites More sharing options...
Verbat Posted January 15, 2008 Author Share Posted January 15, 2008 i am at work so no msn. HAHA i working really hard What is on line 29. We are not mind readers you have to be specific with errors and line numbers. I wrote the line before $query = "SELECT * FROM `table_name` ORDER BY `rating` DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439745 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 post you actual code do you have a table in your database called table_name. How can i help when you don't post the code your using. Quote Link to comment https://forums.phpfreaks.com/topic/86104-php-ranking/#findComment-439749 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.