Jump to content

Finding Overall Position


Zepo.

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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
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.