Get possition

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • I_love_php

    Get possition

    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

  • ninadk@gmail.com

    #2
    Re: Get possition

    for this you can fire the following query

    select * from USERS where user_id=24 order by points desc

    Comment

    • Jerry Stuckle

      #3
      Re: Get possition

      I_love_php wrote:[color=blue]
      > 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
      >[/color]

      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@attgl obal.net
      =============== ===

      Comment

      • I_love_php

        #4
        Re: Get possition

        Thanks alot it is not work but i guess it is a good start let me give u
        example of a table


        ------------------------------------------------------------------------------------
        userid points
        -----------------------------------------------------------------------------------
        3 10
        4 5
        24 15
        4 10
        26 11
        24 10
        3 25
        25 1
        ------------------------------------------------------------------------------------
        as you see user number 24 is have 26 points if we sum all the points
        user have in this table
        what i want to know is the posision of this user
        in the example user 24 will be the 2nd here is the order

        -------------------------------------------------------------------------------
        posistion userid points
        ------------------------------------------------------------------------------
        1 3 35
        ------------------------------------------------------------------------------
        2 24 26
        ------------------------------------------------------------------------------
        3 4 15
        ------------------------------------------------------------------------------
        4 26 11
        ------------------------------------------------------------------------------
        5 25 1
        -----------------------------------------------------------------------------

        i want this in the Best way becouse i want to add it in all pages so i
        dont want my site to be slow

        Comment

        Working...