title: php foreach loop nested increased repeating
body: <p>I've got a loop nested in a loop. All of the data displays fine until I get to the second loop and the returned data keeps repeated. It gets to the point where songs of the items from the second loop gets repeated over 15 times. </p>
  
  <p>item
  -subitems</p>
  
  <p>item
  -subitems
  -subitems</p>
  
  <p>item
  -subitems
  -subitems
  -subitems </p>
  
  <p>item
  -subitems
  -subitems
  -subitems 
  -subitems </p>
  
  <p>I was told to clear my loop but I'm sure how to do that. Any ideas?
  here's a live example if need: view-source:<a href="http://mixtapemonkey.com/json" rel="nofollow">http://mixtapemonkey.com/json</a></p>
  
  <pre><code>&lt;?php 
  include ("connection.php");
  
  foreach($db-&gt;query("SELECT * FROM mixtapes WHERE year='2014' OR year = '2015' ORDER BY id DESC LIMIT 24") as $info) {
  
      echo "mixtape-".$info['id']," {\n";
          echo "\t\"id\" : \"".$info['id']."\",\n";
          echo "\t\"title\" : \"".$info['title']."\",\n";
          echo "\t\"name\" : \"".$info['name']."\",\n";
          echo "\t\"genre\" : \"".$info['genre']."\",\n";
          echo "\t\"year\" : \"".$info['year']."\",\n";
          echo "\t\"downloads\" : \"".$info['downloads']." Downloads\",\n";
          echo "\t\"thumb\" : \"http://mixtapemonkey.com/".$info['thumb']."\",\n";
          echo "\t\"songs\" : {\n";
  
              if ($handle = opendir("mixtapes/zip/".$info['id'])) {
                  while (false !== ($entry = readdir($handle))) {
                      if ($entry != "mixtapes/zip/".$info['id'] &amp;&amp; $entry != "mixtapes/zip/".$info['id']) {   
  
  
                              if ($newhandle = opendir("mixtapes/zip/".$info['id']."/".$entry)) {
                                  while (false !== ($newentry = readdir($newhandle))) {
                                      if ($newentry != "mixtapes/zip/".$info['id']."/".$entry &amp;&amp; $newentry != "mixtapes/zip/".$info['id']."/".$entry) {
  
                                         $ext = substr($newentry, strrpos($newentry, '.') + 1);
                                         if ($ext == "mp3" || $ext == "m4a")
                                          {
                                              $item = "mixtapes/zip/".$info['id']."/".$entry."/";
                                              $musicarray[] = $newentry;
                                              sort($musicarray);
                                          }
                                      }
                                  }
                                  closedir($newhandle);
                              }
  
                      }
                  }
                  closedir($handle);
              }
              foreach ($musicarray as $song) {
  
              echo "\t\t\"track\" : \"http://mixtapemonkey.com/$item$song\",\n";
              }
  
          echo "\t}\n";
      echo "},\n\n";
  }?&gt; 
  </code></pre>