title: PHP Displaying File List repetition
body: <p>Having a problem with my code where I have a routine that lists the files in a directory and you can select one of them to correspond to some table entries (in this case files to be associated with a particular mp3).   The code I have devised below lists all the files once for the first entry but for the second entry lists all of them twice.   I don't understand what has gone wrong...</p>
  
  <pre><code>for ($k=0; $k &lt; $_SESSION[CampaignTrax]; $k++) {
                          $numIncrement = $k +1;
  
  $artistConcentrate = $_POST["ArtistField_".$numIncrement];
  $titleConcentrate = $_POST["TitleField_".$numIncrement];
  $mixConcentrate = $_POST["MixField_".$numIncrement];
  $trackfileConcentrate = "trackFile".$numIncrement;
  
  $myDirectory = opendir(".");
  
  while($entryName = readdir($myDirectory)) {
      $dirArray[] = $entryName;
  }
  
  closedir($myDirectory);
  
  $indexCount = count($dirArray);
  
  sort($dirArray);
  
  echo "&lt;tr&gt;&lt;td&gt;".$numIncrement."&lt;/td&gt;&lt;td&gt;".$artistConcentrate."&lt;/td&gt;&lt;td&gt;".$titleConcentrate."&lt;/td&gt;&lt;td&gt;".$mixConcentrate."&lt;/td&gt;&lt;td&gt;&lt;select name=\"".$trackfileConcentrate."\"&gt;&lt;option value=\"\"&gt;Select File...&lt;/option&gt;";
  
   for($index=0; $index &lt; $indexCount; $index++) {
          if (substr("$dirArray[$index]", 0, 1) != ".") { // don't list hidden files
   echo "&lt;option value=\"".$dirArray[$index]."\"&gt;".$dirArray[$index]."&lt;/option&gt;";
   }
  
  }
  
  echo"&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;";
  }
  
  echo "&lt;/table&gt;";
  </code></pre>
  
  <p>It's probably something simple and as always all help appreciated.</p>
  
  <p>CP</p>