title: Merged multiple pdfs into one wiht PDFMerger
body: <p>I have trying to select multiple PDF files from database and merged them into one. In database is stored the path to the pds's. What I do is to store in session ID's of the rows and then make query to database and select pdfs for each ID. I have faced this problem:</p>
  
  <blockquote>
    <p>It is generated only one PDF the first one from the session array.</p>
  </blockquote>
  
  <p>This is what I have so far:</p>
  
  <pre><code>require_once("database.php");
  include 'PDFMerger.php';
  
  $files = $_SESSION['itemid'];
  print_r($files);
  if(is_array($files)) {
  
  $fileFolder='uploads/';
  $pdf = new PDFMerger;
  
  foreach($files as $file) {
  
      $sql = "SELECT files FROM document_upload WHERE upload_id = :id"; 
      $result = $pdo-&gt;prepare($sql);
      $result-&gt;bindParam(":id", $file);
      $result-&gt;execute();                 
  
      $resArray = $result-&gt;fetchAll();
  
      foreach ( $resArray as $res )
      {
           $items = explode(',', $res["files"]);
  
           foreach ($items as $item) {
  
             $pdf-&gt;addPDF($fileFolder.$item, 'all')
  
              -&gt;merge('browser', 'TEST2.pdf');
           }
      }
  
    }     
  }
  </code></pre>
  
  <p><code>print_r($files);</code> show that all files are in array.</p>
  
  <p><code>print_r($resArray);</code> show only 1 pdf .. first one from the array.</p>