title: PHP/MySQL: simultaneous queries inside WHILE loop?
body: <p>I'm trying to execute a query inside a WHILE loop running on <code>mysqli_fetch_array</code>. The query gives the following error:</p>
  
  <p><code>Error: Commands out of sync; you can't run this command now</code></p>
  
  <p>I found out that you can't have simultaneous queries. Here's my code</p>
  
  <pre><code>$query "SELECT * FROM table";
  $exec = mysqli_query($con, $query);
  
  while($loop = mysqli_fetch_array($exec)){
  
  $data = $loop['data'];
  
  $sim = "SELECT * FROM table2 WHERE col1 = '$data'";
  $execsim = mysqli_query($con, $sim);
  $getsim = mysqli_fetch_array($execsim);
  $somedata = $getsim['somedata'];
  
  //insert $somedata and $data into table3
  
  }
  </code></pre>
  
  <p>After some research, I see that <code>store_result()</code> could be useful here. Excuse my ignorance as this is new to me. There aren't any examples/solutions that I can find that use this with a WHILE loop scenario (<em>does that make a difference?</em>) - most are in object oriented style too.</p>
  
  <p>What is the most effective way around this problem?</p>