Zepo. Posted April 2, 2008 Share Posted April 2, 2008 Ok i want to find the rank or position of a member based on their points. How would i do this? Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/ Share on other sites More sharing options...
darkfreaks Posted April 2, 2008 Share Posted April 2, 2008 <?php $member_points= $_GET['memberpoints']; if($memberpoints=>whatevernumberhere) { //dostuff } elseif ($memberpoints=<whatevernumberhere) { //dostuff }?> Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507763 Share on other sites More sharing options...
Zepo. Posted April 2, 2008 Author Share Posted April 2, 2008 That wont work because i need to pull points from the database of id=$member[id] and i need to find the position of that member based on points. Example ID 1 - 50 points ID 2 - 24 Points ID 3 - 100 Points And $member[id] =3 Then the rank would output 1 and if it was id 2 it would output 3 ect. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507767 Share on other sites More sharing options...
soycharliente Posted April 2, 2008 Share Posted April 2, 2008 <?php $sql = "SELECT * FROM `members` ORDER BY `points`"; $result = mysql_query($sql) OR DIE (mysql_error()); if (mysql_num_rows($result)) { $rank = 0; while ($row = mysql_fetch_array($result)) { $rank++; if ($row['id'] == $id) { exit(); // or is it break() ??? } } } ?> Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507786 Share on other sites More sharing options...
Zepo. Posted April 2, 2008 Author Share Posted April 2, 2008 Thank you very much charlie =]. Your a life saver lol. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507791 Share on other sites More sharing options...
Zepo. Posted April 2, 2008 Author Share Posted April 2, 2008 One problem, exit closes everything after it and break doesn't do anything.. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507796 Share on other sites More sharing options...
darkfreaks Posted April 2, 2008 Share Posted April 2, 2008 change exit() to mysql_close() Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507798 Share on other sites More sharing options...
soycharliente Posted April 2, 2008 Share Posted April 2, 2008 That's why they pay me the big ... bucks ...... wait. I honestly don't know how exit() and break() work in a while loop. I suggest reading up on both to make sure you get the desired effect. One might stop the whole page from running while the other just exits the loop. exit — Output a message and terminate the current script. break — Ends execution of the current for, foreach, while, do-while or switch structure. Sounds like break is a better choice. change exit() to mysql_close() The exit() was to jump outside the while loop, not close the db connection. I didn't add any information about connecting or closing on purpose. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507799 Share on other sites More sharing options...
Zepo. Posted April 2, 2008 Author Share Posted April 2, 2008 I did try break but it gives me this, Parse error: syntax error, unexpected ')' in /home/zepo/public_html/development/v22/index.php on line 1108 That is the line with the break.. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507803 Share on other sites More sharing options...
darkfreaks Posted April 2, 2008 Share Posted April 2, 2008 break; not break() Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507809 Share on other sites More sharing options...
soycharliente Posted April 2, 2008 Share Posted April 2, 2008 DELETED. Irrelevant. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507810 Share on other sites More sharing options...
soycharliente Posted April 2, 2008 Share Posted April 2, 2008 break; not break() Oh wow. I'm really dumb. No excuses. I'm sorry for telling you wrong syntax. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507812 Share on other sites More sharing options...
darkfreaks Posted April 2, 2008 Share Posted April 2, 2008 no problem mate just a correction Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507813 Share on other sites More sharing options...
Zepo. Posted April 2, 2008 Author Share Posted April 2, 2008 NVM, changed to order by points DESC and it all works, thanks again. Works perfectly =]. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507815 Share on other sites More sharing options...
soycharliente Posted April 2, 2008 Share Posted April 2, 2008 Post a little more code. Where is $member[id] coming from? I picked a random table name and a random field name that sounded like what you needed. Is the database setup like that? Echo the query to see exactly what it's pulling. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507817 Share on other sites More sharing options...
soycharliente Posted April 2, 2008 Share Posted April 2, 2008 Did you change your post? LOL Little errors are the worst. Mark solved please. Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507819 Share on other sites More sharing options...
darkfreaks Posted April 2, 2008 Share Posted April 2, 2008 hit solved topic shud be in left corner Link to comment https://forums.phpfreaks.com/topic/99240-finding-overall-position/#findComment-507822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.