Results 1 to 2 of 2

Thread: MySQL Query question

  1. #1
    Join Date
    Feb 2010
    Posts
    29

    MySQL Query question

    I'm doing a ranking system which includes searching someone's rank. When the result is returned, I want to show the two people before that person and the two people after that person. I'm not sure of what type of query I would use.

    My standard query would be $mysqli->query("SELECT rank,name FROM users WHERE name = '$search' LIMIT 1");
    but in this case, I want to also retrieve the other users as well.

    Rank Name
    50 Person1
    51 Person2
    53 SEARCH RESULT
    54 Person4
    55 Person5

  2. #2
    Join Date
    Dec 2009
    Location
    San Diego, California
    Posts
    161
    Some pseudo code for you:

    1. Get Rank of Person
    SELECT rank, name FROM users WHERE name='$search' LIMIT 1

    2. Calculate Min and Max rank
    $rank_max = $rank + 3;
    $rank_min = $rank - 2;

    3. Get Range of People
    SELECT rank, name FROM users WHERE rank < $rank_max AND rank > $rank_min LIMIT 5

    Get what I mean?

Similar Threads

  1. order by date in mysql query
    By Alx in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 07 Feb 2009, 05:16 AM
  2. php mysql query
    By pompeyjohn in forum General Questions
    Replies: 0
    Last Post: 09 Aug 2006, 05:13 AM

Posting Permissions

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