title: insert query inside select query loop
body: <p>I've created below function which include several mysql queries, which seem to create an issue. Cause when I run this function it returns following error:</p>
  
  <blockquote>
    <p>Errormessage: Commands out of sync; you can't run this command now</p>
  </blockquote>
  
  <p>I've tried to include <code>next_result()</code>, but does not do any difference?</p>
  
  <pre><code>function retrievePlayerTweets(){
      global $con;
      $query = $con-&gt;prepare("Select players.fullname, players.twitter_user, team.id as teamId FROM players, team WHERE players.teamId = team.id");
      $query-&gt;execute();
      $query-&gt;bind_result($fullname, $twitter_user, $teamId);
  
      while ($query-&gt;fetch()) {
  
          foreach(retrieveUserTweets($twitter_user) as $twitterData) {
              $id = $twitterData['id_str'];
              $text = $twitterData['text'];
              $name = $twitterData['user']['name'];
              $dateString = $twitterData['created_at'];
              $favoriteCount = $twitterData['favorite_count'];
              $date = date('Y-m-d H:i:s', strtotime($dateString));
  
              if ($insert_tweet = $con-&gt;prepare("INSERT IGNORE INTO tweets (`fullname`, `username`, `text`, `created`, `teamId`, `twitterId`, `favoriteCount`) VALUES (?, ?, ?, ?, ?, ?, ?)")) {
  
                  $insert_tweet-&gt;bind_param("ssssisi", $name, $twitter_user, $text, $date, $teamId, $id, $favoriteCount);
                  $insert_tweet-&gt;execute();
                  $con-&gt;next_result();
  
              } else {
                  die("Errormessage: ". $con-&gt;error);
              }
          }
      }
  }
  </code></pre>