Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts

    select all from a database and find position of a certain entry

    I need to list everything from a database order by a certain field, which i can do, however i almost need to find the position of a entry (WHERE `userID` = '$userID') that would be the criteria, how would i do that? I can do a full DB search and a WHERE criteria search but i can figure out how to do a mix of both.

    EDIT: This would be done in PHP if that makes any difference.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,340 Times in 4,306 Posts
    Ummm...

    Code:
    SELECT list, of, fields
    FROM tablename
    WHERE somecondition
    ORDER BY somefield
    The parts of a SELECT must be given in that order.

    There are other parts that can be used, of course:
    Code:
    SELECT
    FROM 
    WHERE
    GROUP BY
    HAVING
    ORDER BY 
    LIMIT
    when used, they must be used in that order. (And there are even other much more rarely used parts that have to be in a particular order...and then there are joins and unions and subselects...but the above are the basic parts.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •