title: Query SQL Limit
body: <p>TABLES</p>
  
  <p>PLAYERS</p>
  
  <pre><code>id | name    | rank id
  1  | player1 | 3
  2  | player2 | 0
  3  | player3 | 0
  4  | player4 | 1
  5  | player5 | 0
  6  | player6 | 0
  </code></pre>
  
  <p>GUILDS</p>
  
  <pre><code>id | name
  1  | test1
  2  | test2
  </code></pre>
  
  <p>GUILD RANKS</p>
  
  <pre><code>id | guild_id
  1  |  1 &lt;- which is test
  2  |  2 &lt;- which is test2
  </code></pre>
  
  <p>QUERY</p>
  
  <pre><code>$player = query -&gt; name
  $player_id = $SQL-&gt;query('SELECT rank_id from players where name = "'.htmlspecialchars($player['name']).'"')-&gt;fetch();
  $player_id = $player_id['rank_id'];
  $has_guild = $SQL-&gt;query('SELECT guild_id from guild_ranks where id = '. $player_id .'')-&gt;fetch();
  $has_guild = $has_guild['guild_id'];
  if($has_guild == 0){
      $guild_d_player = "No Guild";
  }else{
      $guild_do_player = $SQL-&gt;query('SELECT name from guilds where id = '.$has_guild.' &gt; 0')-&gt;fetch();
      $guild_do_player = $guild_do_player ['name'];
      $guild_d_player = "";
  }
  </code></pre>
  
  <p>This is what happen with this:</p>
  
  <p>This is about guilds.</p>
  
  <p>Example:</p>
  
  <pre><code>Name    |   Guild Name   | This player truly is in a guild?
  
  Player1 |      Test      | Yes
  
  Player2 |  TestNo Guild  | &lt;- Here is the problem, this player doesn't have guild but seems like if he was on one.
  
  Player3 |  TestNo Guild  | No
  
  Player4 |      Test2     | Yes
  
  Player5 |  Test2No Guild | No
  
  Player6 |  Test2No Guild | No
  
  Etc...
  </code></pre>
  
  <p>It repeat the guild name until the query get a new guild name which truly exist.</p>
  
  <p>Full query: <a href="http://pastebin.com/03TYv9V9" rel="nofollow">http://pastebin.com/03TYv9V9</a></p>