title: Query Database inside a loop
body: <p>I have multiple dropdown menus. When the user clicks submit button. The isset function in the if clause is triggerd and the following code gets executed</p>
  
  <pre><code> if(isset($_POST["submit"]))
    {
       $player_id = $_REQUEST['players'];
       var_dump ($player_id);
              for($i=0; $i &lt; sizeof($player_id); $i++) //query database with different player_id each time
              {
                  foreach ($player_id as $id){
                      $query = 'SELECT `name`  FROM `player_info`
                      WHERE `player_id` = '.$id;
                      $return_names = mysql_query($query) or die(mysql_error());
                                              }
                          while($row = mysql_fetch_array($return_names))
                          {
                              $selected[] = $row['name'];     
                          }                   
                          var_dump($selected);
                      }
                  }
  </code></pre>
  
  <p>What the above code should do is return the names, of the players, the user selected. However when I open it I get this:</p>
  
  <p><img src="https://i.stack.imgur.com/EaqAJ.jpg" alt="enter image description here"></p>
  
  <p>Notice the $player_id array which I use in the 1st var_dump holds the different player_id values.</p>
  
  <p>However when I do a var_dump on the second array $selected the array contains only the values "Burger"</p>
  
  <p>I suspect the problem is in the foreach loop and the way I query the database. If someone could point me in the right direction it would be greatly appreciated.
  Thanks in advance.</p>