title: How to create foreach loop value dynamically table mpdf?
body: <p>I am beginner PHP developer. I'm using mPDF library and I'm trying to write a code which will create multiple table value showing. The problem is that always only the first value only showing.</p>
  
  <p>I can't figure out how to solve this. Would someone lead me on the right path? My logic is:</p>
  
  <ul>
  <li>I have one array with all of orders; for each order I would like to create PDF. </li>
  <li>I loop the array and each time call the MPDF library </li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php
  
  require_once "clientinvoice.php";
  
  $inNumber = $record['ginvo_client_invoice_no'];
  
  
  $count = 0;
  $index = 0;
  
  foreach ($invoices as $invoice) {
      $count+=$invoice['rate_with_vat'];
  }
  
  $invAmount = number_format((float)$count, 2, '.', '');
  
  //vendor name generate
  if ($_GET['showVendor']==1) {
      foreach ($vendorDetails as $vendorDetail) {
            if($vendorDetail['id']==$invoice['vendor_id']){
                  $vendor_name = $vendorDetail['first_name'];
                  $address_treet = $vendorDetail['address_street'];
                  $address_city = $vendorDetail['address_city'];
                  $address_state = $vendorDetail['address_state'];
                  $address_country =$vendorDetail['address_country'];
                  $postal_cod = $vendorDetail['address_postalcode'];
              }
      }
      $vendorAddress = $vendor_name .','. $address_treet.','. $address_city.','. $address_state.','. $address_country.','. $postal_cod;
      $tdClass = 'vendorDt';
  }else {
      $vendorAddress = '';
      $tdClass = '';
  }
  
  //proforma invoice display
  if ($proforma_invoice_amount&gt;0&amp;&amp;$record['proforma_invoice_c'] == 'yes') {
  
      $profomaAmount = number_format((float)$proforma_invoice_amount, '2', '.', '');
      $resttoPay = $count - $profomaAmount;
      $restPay = number_format((float)$resttoPay, '2', '.', '');
      $proTrClass = '';
  }else {
      $proTrClass = 'proformaFooter';
  }
  
  if ($record['client_location_c'] == 'germany') {
      $thanks = '&lt;p&gt;Thank you for your order';
  
      $footerAddress = '&lt;tr&gt;&lt;td colspan="7" style="display:flex;justify-content:space-between;"&gt;&lt;div class="manufacture-address"&gt;&lt;div class="display-flex" style="text-align:center"&gt;
      &lt;div class="text-left" style="width:33%"&gt;
              &lt;p&gt;
                      &lt;span&gt;Global Guide Services GmbH&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;Münchner Str. 23&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;D-83703 Gmund a. Tegernsee&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;Local Court Munich, HRB 223121&lt;/span&gt;
              &lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="text-center" style="text-align:center;width:33%;position:absolute;bottom:0px;margin-left:60%;margin-top:-12%;"&gt;
              &lt;p&gt;
                      &lt;span&gt;Managing Director: Siavash Sartipi&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;&lt;i class="fa fa-phone"&gt;&lt;/i&gt; +49 151 74327305&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;&lt;i class="fa fa-print"&gt;&lt;/i&gt; +49 721 509663197&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;www.global-guide-services.com&lt;/span&gt;
              &lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="text-right" style="text-align:center;width:33%;position:absolute;bottom:0;right:10px;margin-top:-12%;" &gt;
              &lt;p&gt;
                      &lt;span&gt;VAT Nr DE 305563525&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;Tax Nr 139/127/50609&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;IBAN DE41 7001 0080 0697 1208 00&lt;/span&gt;&lt;br&gt;
                      &lt;span&gt;BIC/SWIFT PBNKDEFF&lt;/span&gt;
              &lt;/p&gt;
      &lt;/div&gt;
  &lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;';
  
  }else {
      $thanks = '&lt;p&gt;Intocmit de: Andreea loana&lt;/p&gt;&lt;br/&gt;
      &lt;div class="cnp"&gt;&lt;span&gt;CNP: 2950318151935&lt;/span&gt;&lt;/div&gt;';
  
      $footerAddress = '&lt;tr&gt;&lt;td colspan="7" style="text-align:center;"&gt;&lt;div class="manufacture-address"&gt;&lt;div class="text-center address_Raif" style="text-align:center"&gt;
          &lt;p&gt;
                  &lt;span&gt;Account holder: &lt;label&gt;Global Guides Services SRL,&lt;/label&gt; Bank:Raiffeisen&lt;/span&gt;&lt;br&gt;
                  &lt;span&gt;IBAN RO 92 RZBR 0000 0600 1754 9626 BIC(SWIFT):RZBRROBU&lt;/span&gt;&lt;br&gt;
                  &lt;span&gt;VAT: RO34622172&lt;/span&gt;&lt;br&gt;
          &lt;/p&gt;
      &lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;';
  }
  
  //footer address display
  
  
  $html = '
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta name="description" content=""&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;style&gt;
  body {
      font-family: Arial, Verdana, Helvetica, sans-serif !important;
      font-size: 14px !important;
      background: #efefef;
      -webkit-print-color-adjust: exact;
      width: 960px;
          line-height:1 !important;
      margin: 0 auto;
  }
  table.report {
      border-collapse: collapse;
      width: 100%;
  }
  .invoice-head h3 {
      text-transform: uppercase;
      margin-bottom: 0;
      font-size: 16px;
      word-spacing: -2px;
      padding: 5px;
  }
  p { margin: 0pt; }
  // table.items {
  //  border: 0.1mm solid #000000;
  // }
  td { vertical-align: top; }
  // .items td {
  //  border-left: 0.1mm solid #000000;
  //  border-right: 0.1mm solid #000000;
  // }
  table thead td { background-color: #EEEEEE;
      text-align: center;
      // border: 0.1mm solid #000000;
      font-variant: small-caps;
  }
  .items td.blanktotal {
      background-color: #EEEEEE;
      border: 0.1mm solid #000000;
      background-color: #FFFFFF;
      border: 0mm none #000000;
      border-top: 0.1mm solid #000000;
      border-right: 0.1mm solid #000000;
  }
  .items td.totals {
      text-align: right;
      border: 0.1mm solid #000000;
  }
  .items td.cost {
      text-align: "." right;
  }
  .headerBorder{
      border-bottom:3px solid #344d90;
  }
  .invoice-head {
      text-align: center;
      position: relative;
  }
  .invoice-head .invoice_head-bg {
      height: 61px;
      position: absolute;
      z-index: -1;
      width: 100%;
      background: #d4d2d2;
      -webkit-print-color-adjust: exact;
  }
  .img-gradient {
      position: absolute;
      right: 39px;
      top: 0;
      height: 250px;
      width: 200px;
      z-index: -1;
      background: #bdc9ec;
      background: -webkit-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
      background: -o-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
      background: -moz-linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
      background: linear-gradient(#bdc9ec, rgba(107, 113, 181, 0));
      -webkit-print-color-adjust: exact;
  }
  .topRight{
      position:absolute;
      right:60px;
      top:3%;
  }
  .table-header th, .table-body td, .table-footer td {
      padding: .70rem;
      vertical-align: top;
      border-top: 1px solid #eceeef;
      width: 13%;
  }
  .text-right {
      text-align: right;
      font-style: initial;
  }
  .vendorDt{
      background-color: rgba(123, 159, 234, 0.26);-webkit-print-color-adjust: exact;
  }
  .footer{
  background: #a9b8e2;-webkit-print-color-adjust: exact;margin-top: -20% !important;margin-bottom: 50% !important;
  }
  .footer td{
  text-transform:uppercase;text-align:right;
  }
  .proformaFooter{
      display:none;
  }
  
  .manufacture-address {
      text-align: center;
  }
  .invoice-details {
       display: flex;
  }
  
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;!--mpdf
  &lt;htmlpageheader name="myheader"&gt;
  &lt;table width="100%" class="report"&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;img src="images/company_logo.png" alt="" style="width:150px"&gt;&lt;/td&gt;
  &lt;/tr&gt;&lt;/table&gt;
  &lt;div class="headerBorder"&gt;&lt;/div&gt;
  &lt;/htmlpageheader&gt;
  
  &lt;htmlpagefooter name="myfooter"&gt;
  &lt;div style="border-top: 1px solid #344d90; text-align: center; padding-top: 1mm; "&gt;&amp;nbsp;&lt;/div&gt;
  &lt;table width="100%" class="report"&gt;
  &lt;tbody&gt;'.$footerAddress.'&lt;/tbody&gt;
  &lt;/table&gt;
  
  &lt;/htmlpagefooter&gt;
  
  &lt;sethtmlpageheader name="myheader" value="on" show-this-page="1" /&gt;
  &lt;sethtmlpagefooter name="myfooter" value="on" /&gt;
  mpdf--&gt;
  &lt;div class="img-gradient"&gt;&amp;nbsp;&lt;/div&gt;
  &lt;table width="100%" style="font-family: arial;" cellpadding="0"&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td colspan="3"&gt;
  &lt;div class="address-left"&gt;
      &lt;p&gt;&lt;strong&gt;client.invoice@global-guide-services.com&lt;/strong&gt;&lt;/p&gt;&lt;br/&gt;
      &lt;span&gt;'.$record['client_name'].'&lt;/span&gt;&lt;br&gt;
      &lt;span&gt;'.$record['client_address'].'&lt;/span&gt;&lt;br&gt;
      &lt;span&gt;'.$record['client_address_city'].'&lt;/span&gt;&lt;br&gt;
      &lt;span&gt;'.$record['client_address_state'].', '.$record['client_address_country'].'&lt;/span&gt;&lt;br&gt;
      &lt;span&gt;'.$record['client_address_postalcode'].'&lt;/span&gt;&lt;br&gt;
      &lt;span style="font-weight:bold;margin-top:25px;"&gt;'.$clientvatId.'&lt;/span&gt;
  &lt;/div&gt;&lt;/td&gt;
  &lt;td colspan="4" style="text-align:right"&gt;
  &lt;div class="topRight"&gt;&lt;h3&gt;'.$country.'&lt;/h3&gt;&lt;/div&gt;
  &lt;div class="address-right"&gt;
    &lt;p&gt;'.$address.'&lt;/p&gt;
    &lt;p&gt;
          &lt;span&gt;&lt;i class="fa fa-phone '.$phone.'"&gt;&lt;/i&gt;'.$record['recipient_phone_number_c'].'&lt;/span&gt;&lt;br&gt;
          &lt;span&gt;&lt;i class="fa fa-print '.$fax.'"&gt;&lt;/i&gt;'.$record['recipient_fax_number_c'].'&lt;/span&gt;
    &lt;/p&gt;
  &lt;/div&gt;&lt;/td&gt;
  
  &lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan="7" style="margin-bottom:2px;"&gt;&lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;br /&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;div class="invoice_head-bg" style="background-color:#ccc;height:25px"&gt;&lt;/div&gt;
  &lt;td colspan="7" style="line-height:1.50;margin-top:10% !important;text-align:center;position:relative;-webkit-print-color-adjust: exact;background-color:#ccc;"&gt;
    &lt;div class="invoice-head"&gt;
      &lt;h3 style="text-transform: uppercase;margin-bottom:0;font-size:13px;word-spacing:-2px;padding:5px;"&gt;'.$invoice_title.'&lt;/h3&gt;
      &lt;p style="margin-top: 25px;font-size: 14px;word-spacing: 4px;"&gt;for the assignment of guided tours, assistances, tour escorts, transfers&lt;/p&gt;
    &lt;/div&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;br /&gt;
  &lt;tr&gt;
  &lt;td colspan="7" style="display: flex;line-height:1.75;"&gt;
  &lt;div class="invoice-details"&gt;
      &lt;div class="invoice-number"&gt;
        &lt;p&gt;&lt;strong&gt;Invoice number :&lt;/strong&gt; &lt;span&gt;'.$record['ginvo_client_invoice_no'].'&lt;/span&gt;&lt;/p&gt;
        &lt;p&gt;&lt;strong&gt;Invoice date :&lt;/strong&gt; &lt;span&gt;'.$inv_date.'&lt;/span&gt;&lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="invoice-info" style="position:absolute;right:7%;top:31%;"&gt;
        &lt;span&gt;(please invoice number and date with your payment)&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;br /&gt;
  &lt;table class="items" width="100%" style="" cellpadding="8" cellspacing="0"&gt;
  &lt;thead&gt;
  &lt;tr style="background: #7d93ce;"&gt;
  &lt;th&gt;Group Id&lt;/th&gt;
  &lt;th&gt;Date&lt;/th&gt;
  &lt;th&gt;City&lt;/th&gt;
  &lt;th&gt;Service&lt;/th&gt;
  &lt;th&gt;Duration&lt;/th&gt;
  &lt;th&gt;Note&lt;/th&gt;
  &lt;th&gt;Rate &amp;euro;&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td&gt;'.$invoice['group_id'].'&lt;/td&gt;
  &lt;td&gt;'.$invoice['service_date'].'&lt;/td&gt;
  &lt;td&gt;'.$invoice['city'].'&lt;/td&gt;
  &lt;td&gt;'.$invoice['service'].'&lt;/td&gt;
  &lt;td&gt;'.$invoice['duration'].'&lt;/td&gt;
  &lt;td&gt;'.$invoice['notes'].'&lt;/td&gt;
  &lt;td class="cost"&gt;&amp;euro; '.$invoice['rate_with_vat'].'&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr class='.$tdClass.'&gt;
  &lt;td colspan="7" style="text-align:center"&gt;'.$vendorAddress.'&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;!-- END ITEMS HERE --&gt;
  &lt;tr class="footer"&gt;
  &lt;td class="text-right" colspan="6"&gt;&lt;strong&gt;Total Sum&lt;/strong&gt;&lt;/td&gt;
  &lt;td class="text-right"&gt;&lt;b&gt;&amp;euro; '.$invAmount.'&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;div class="'.$proTrClass.'"&gt;
  &lt;tr class="footer"&gt;
  &lt;td class="text-right" colspan="6"&gt;&lt;strong&gt;Paid with Proforma&lt;/strong&gt;&lt;/td&gt;
  &lt;td class="text-right"&gt;&lt;b&gt;&amp;euro; '.$profomaAmount.'&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr class="footer"&gt;
  &lt;td class="text-right" colspan="6"&gt;&lt;strong&gt;Rest to Pay&lt;/strong&gt;&lt;/td&gt;
  &lt;td class="text-right"&gt;&lt;b&gt;&amp;euro; '.$restPay.'&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/div&gt;
  &lt;/tbody&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td colspan="7" style="text-align:right"&gt;
  &lt;div class="vat text-right"&gt;
  &lt;span&gt;'.$reverse.'&lt;/span&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="7"&gt;
  &lt;div class="invoice-include"&gt;
  &lt;p&gt;'.$content.'&lt;/p&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="7"&gt;
  &lt;div class="invoice-dueDate"&gt;&lt;p&gt;Our invoice falls due immediately and is to be paid in full within&lt;/p&gt;
  &lt;div class="date"&gt;&lt;span style="margin: 15px 40px;position:relative;right:10px;"&gt;'.$due_date.'&lt;/span&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="7"&gt;
  &lt;div class="thanks"&gt;'.$thanks.'&lt;/div&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  ';
  //==============================================================
  //==============================================================
  //==============================================================
  //==============================================================
  //==============================================================
  //==============================================================
  
  define('_MPDF_PATH','../custom/mpdf/');
  include("../custom/mpdf/mpdf.php");
  
  $mpdf=new mPDF('c','A4','','',10,10,29,35,10,5);
  $mpdf-&gt;SetProtection(array('print'));
  $mpdf-&gt;SetTitle($inNumber);
  $mpdf-&gt;SetAuthor("Venkatesh");
  $mpdf-&gt;showWatermarkText = true;
  $mpdf-&gt;watermark_font = 'DejaVuSansCondensed';
  $mpdf-&gt;watermarkTextAlpha = 0.1;
  $mpdf-&gt;SetDisplayMode('fullpage');
  
  
  
  $mpdf-&gt;WriteHTML($html);
  
  
  $mpdf-&gt;Output($inNumber.'.pdf', 'I'); exit;
  
  exit;
  
  ?&gt;
  </code></pre>