| Posted by Jerry Stuckle on 08/26/05 00:08 
I_love_php wrote:> hello i have this table
 >
 > (USERS )
 > witch have
 > game_id
 > user_id
 > points
 >
 >
 > ---------
 >
 > in every game user can win points ... what i want is the best way to
 > Get the position of the user
 >
 > lets say i want to get the position of the user number 24 ...(up to the
 > points ) higher points in the Frist and the lowest points in the last
 >
 > Thanks in advance
 >
 
 You didn't say which database or version you're running, but if it supports
 subselects something like this might work (warning - not tested):
 
 SELECT count(user_id) FROM table WHERE points > (SELECT points FROM table
 WHERE user_id = 24);
 
 Then add 1 to get the user's position.  Don't use >= because your user might be
 tied with 20 other users - and you'll get an incorrect result.
 
 If your database doesn't support subselects, just do this in two different
 SELECT statements (get the points for user_id=24 and use it in the WHERE clause
 of the first select).
 
 --
 ==================
 Remove the "x" from my email address
 Jerry Stuckle
 JDS Computer Training Corp.
 jstucklex@attglobal.net
 ==================
  Navigation: [Reply to this message] |