title: Mysqli_query inside of a foreach loop
body: <p>I'm having trouble with a mysqli_query from inside a foreach loop, I'm getting a string from a table first, then separating that into an array. Then I try looping through the array and calling a query inside the loop.</p>
  
  <pre><code>$langs_result = mysqli_query($con, "SELECT Languages FROM users WHERE Username = '$username'");
  
      $row = mysqli_fetch_assoc($langs_result);
  
      $langs = $row['Languages'];
      $userLangs = str_replace(" ","",$langs);
      $userLangs = explode(",",$langs);
      print_r($userLangs);
      $posts = array();
  
      foreach($userLangs as $lang){
          echo "$lang &lt;br&gt;";
          $sql = "SELECT * FROM posts WHERE Language = '$lang'";
          $getLangPosts = mysqli_query($con, $sql);
          array_push($posts, mysqli_fetch_assoc($getLangPosts));
      }
  
      print_r($posts);
  </code></pre>
  
  <p>for this user the langusges are German, Italian, Danish, and English, but the <code>$posts</code> array only contains the first post found from the first language (German), can anybody help? I am trying to get all of the posts for each language in the <code>$userLangs</code> array.</p>
  
  <p>It's going through the <code>foreach</code> loop okay as the <code>$lang</code> variable that's echoed changes each time but the query still isn't working properly.</p>
  
  <p>Thanks for the help!</p>