title: Mysql Select query - not able to limit records
body: <p>I have a ranking table in which i have all players with their ranks.</p>
  
  <pre><code>id | rank | playername | is_available | ranking_name   | ranking_id
  -------------------------------------------------------------------
   1 |  1   | testname1   |     1        | australia open |   1
   2 |  2   | testname2   |     1        | australia open |   1
   3 |  3   | testname3   |     0        | australia open |   1
   4 |  4   | testname4   |     1        | australia open |   1
   5 |  1   | testname5   |     1        | japan open     |   2
  </code></pre>
  
  <p>This table is huge and for each ranking_id there can be more than 500 players.
  Now every player can challenge a match to upper players x% above him. This x is set by superadmin. If x = 10, player "testname4" can challenge (num of players in a ranking_id * 10/100) = 4*10/100=0.4 round to 1. so testname4 can challenge one one player above him. But his above player "testname3" is not available. So he should be given next available player. I want the output like</p>
  
  <pre><code>//testname4 can challenge below players
  
  id | rank | playername | status        |
  --------------------------------------
   2 | 2    | testname2  |   available   |
   3 | 3    | testname3  | not available |
  </code></pre>
  
  <p>What i did:</p>
  
  <pre><code> //testname4 wants to challenge. So i know his rank and other information
  
   $selectSql = mysql_query("SELECT * from rankingTable where ranking_id = 1 AND rank &lt; 4");
  </code></pre>
  
  <p>This is giving me "testname1" record as well. how can i limit this ? And most biggest problem is i need to show the ranks in ascending order. Its not easy using order by here.</p>