title: Is it ok to query inside a while loop?
body: <p>I have two tables in one database. I am querying the first table limit by 10 then loop the results. And inside the while loop, I am doing again another query using a data from the first query as a parameter. Here is an example of the script:</p>
  
  <pre><code>&lt;?php
  
      $con = mysql_connect(host,username,password);
      mysql_select_db(game_server);
  
      //My first query
      $q1 = mysql_query('SELECT * FROM game_characters ORDER BY score DESC LIMIT 10');
  
      while($character = mysql_fetch_object($q1)){
      //My second query
          $q2 = mysql_query('SELECT * FROM game_board WHERE id="'.$character-&gt;id.'"');
          $player = mysql_fetch_object($q2);
      }
  ?&gt;
  </code></pre>
  
  <p>So if I have a result of 100 rows, then the second query will execute 100 times. And I know it is not good. How can I make it better. Is there a way to do everything in one query? What if there is another query inside the while loop where a data from the second query as a parameter is used?</p>
  
  <blockquote>
    <p>P.S.: I am doing a rankings system for an online game.</p>
  </blockquote>