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.

<?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() ???
	}
}
}
?>

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.

Archived

This topic is now archived and is closed to further replies.

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