title: PHP Alternative to using a query within a loop
body: <p>I was told that it is a bad practice to use a query (select) within a loop because it slows down server performance.</p>
  
  <p>I have an array such as</p>
  
  <pre><code>Array ( [1] =&gt; Los Angeles )
  Array ( [2] =&gt;New York)
  Array ( [3] =&gt; Chicago )
  </code></pre>
  
  <p>These are just 3 indexes. The array I'm using does not have a constant size, so sometimes it can contain as many as 20 indexes.</p>
  
  <p>Right now, what I'm doing is (this is not all of the code, but the basic idea)</p>
  
  <ol>
  <li>For loop</li>
  <li>query the server and select all people's names who live in "Los Angeles"</li>
  <li>Print the names out</li>
  </ol>
  
  <p>Output will look like this:</p>
  
  <pre><code>Los Angeles
        Michael Stern
        David Bloomer
        William Rod
  
  New York
        Kary Mills
  
  Chicago
        Henry Davidson
        Ellie Spears
  </code></pre>
  
  <p>I know that's a really inefficient method because it could be a lot of queries as the table gets larger later on.</p>
  
  <p>So my question is, is there a better, more efficient way to SELECT information based on the stuff inside an array that can be whatever size?</p>