title: Nested while-loops php
body: <p>I am breaking my neck over this problem. So I have a text file "$file" that I am reading line by line with the first while-loop. This is working; when I echo the "$usertext" in there, it prints nicely all the lines that are in the file.</p>
  
  <p>So I want to use the $usertext as a condition for my DB query and then loop through all the rows of the DB that meet that condition. Somehow only the last line of $usertext gets in the while-loop (it is the only one that gets printed when I echo $usertext in the second while-loop).</p>
  
  <p>Why do not all lines of my text file go through the second while-loop?</p>
  
  <pre><code>if ($file) {
   while (($line = fgets($file)) !== false) {
    $usertext = $line;
    echo $usertext."\n";
  
    $result = $db-&gt;query("SELECT user, artist, artist_mbid, track, track_mbid, COUNT(*) as playcount FROM users WHERE user='$usertext' GROUP BY artist, track, user");
  
    while($row=$result-&gt;fetchArray()){
     echo $usertext."\n"; 
       //I also used $row["user"]; does not make any difference
    }
   } 
  }
  </code></pre>