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? Quote Link to comment 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 }?> Quote Link to comment 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. Quote Link to comment 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() ??? } } } ?> Quote Link to comment 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. Quote Link to comment 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.. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 2, 2008 Share Posted April 2, 2008 change exit() to mysql_close() Quote Link to comment 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. Quote Link to comment 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.. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 2, 2008 Share Posted April 2, 2008 break; not break() Quote Link to comment Share on other sites More sharing options...
soycharliente Posted April 2, 2008 Share Posted April 2, 2008 DELETED. Irrelevant. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted April 2, 2008 Share Posted April 2, 2008 no problem mate just a correction Quote Link to comment 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 =]. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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.