title: New pdf for every different customer number
body: <p>I have tried to cut down the code as much as possible. The most important part of the code is the second block. There are only two scenarios where I need a different bill to address. These are hard coded in shippercarrierdata,shippercarrierdata1.These create pdfs fine. the problem is creating the default addresses for prepaid customers when there is more than one customer I need it to create a new pdf with a list of all the orders for that customer. I am using TCPDF. Any help would be appreciated. </p>
  
  <pre><code>&lt;?php
      //
      include('inc/connections.php');
      $pickUpDate = $_REQUEST['pickUpDate'];
  
      require_once('tcpdf/config/lang/eng.php');
      require_once('tcpdf/tcpdf.php');
  
      // Extend the TCPDF class to create custom Header and Footer
      class ManafestPrint extends TCPDF {
  
          //Page header
          public function Header()
          {
              global $pickUpDate;
  
              // Set font
              $this-&gt;SetFont('helvetica', 'B', 20);
              // Title
              $titleHTML = '
                      &lt;table width="100%" border="0" style="font-weight: bold; font-size: 9pt;"&gt;
                          &lt;tr&gt;
                              &lt;td width="25%" align="left"&gt;PICK UP DATE: '.$pickUpDate.'&lt;/td&gt;
                              &lt;td width="50%" align="center" style="font-size: 16pt;"&gt;SHIPPING MANIFEST&lt;/td&gt;
                              &lt;td width="25%" align="right"&gt;Page '.$this-&gt;getPageNumGroupAlias().' of '.$this-&gt;getPageGroupAlias().'&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  ';
              $this-&gt;writeHTMLCell(280, 25, 7, 5, $titleHTML);
          }
  
  
      }
      $orders = explode(',', $_REQUEST['orders']);
      $infinity = '';
      $i = 0;
      foreach($orders as $order) {
  
  
          $sql = "
                  SELECT
                      oeordhdr_sql.ship_via_cd AS shipper,
                      oeordlin_sql.ord_no AS ordnum,
                      oeordhdr_sql.frt_pay_cd AS thirdparty,
                      oeordhdr_sql.cus_no AS customer
                  FROM oeordhdr_sql JOIN oeordlin_sql ON oeordhdr_sql.ord_no = oeordlin_sql.ord_no
                  WHERE
                      oeordhdr_sql.ord_no = oeordlin_sql.ord_no
                      AND oeordlin_sql.loc IN ('PMD','OM1')
                      AND oeordhdr_sql.shipping_dt&gt;=getdate()-21
                      AND oeordlin_sql.ord_no = ' $order'
                      ORDER BY oeordlin_sql.ord_no ASC
              ";
          $query = odbc_exec($connect, $sql);
          $row = odbc_fetch_array($query);
      if (($row['customer']) == '0000' &amp;&amp; ($row['thirdparty']) == 'C' &amp;&amp; ($row['shipper']) == 'EST') {
      $tablerows= "&lt;tr&gt;&lt;td&gt;'.$row['customer'].'&lt;/td&gt;&lt;td&gt;'.$row['customer'].'&lt;/td&gt;&lt;td&gt;'.$row['ord_num'].'&lt;/td&gt;&lt;td&gt;'.$row['item_no'].'&lt;/td&gt;&lt;td&gt;'.$row['shipper'].'&lt;/td&gt;&lt;td&gt;'.$row['thirdpart'].'&lt;/td&gt;&lt;/tr&gt;";
      }elseif (($row['customer']) == '0001' &amp;&amp; ($row['thirdparty']) == 'C' &amp;&amp; ($row['shipper']) == 'EST') {
      $tablerows1 = "&lt;tr&gt;&lt;td&gt;'.$row['customer'].'&lt;/td&gt;&lt;td&gt;'.$row['customer'].'&lt;/td&gt;&lt;td&gt;'.$row['ord_num'].'&lt;/td&gt;&lt;td&gt;'.$row['item_no'].'&lt;/td&gt;&lt;td&gt;'.$row['shipper'].'&lt;/td&gt;&lt;td&gt;'.$row['thirdpart'].'&lt;/td&gt;&lt;/tr&gt;";
      }else{
      $tablerows2 = "&lt;tr&gt;&lt;td&gt;'.$row['customer'].'&lt;/td&gt;&lt;td&gt;'.$row['customer'].'&lt;/td&gt;&lt;td&gt;'.$row['ord_num'].'&lt;/td&gt;&lt;td&gt;'.$row['item_no'].'&lt;/td&gt;&lt;td&gt;'.$row['shipper'].'&lt;/td&gt;&lt;td&gt;'.$row['thirdpart'].'&lt;/td&gt;&lt;/tr&gt;";
      }
      }
      $tableData = '
              &lt;style&gt;
                  table#manifestTable tr.odd td{
                      background-color: #F0F0F0;
                  }
                  div.totalDIV{
                      vertical-align: bottom;
                      font-weight: bold;
                  }
              &lt;/style&gt;
              &lt;table id="manifestTable" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 8pt;"&gt;
                  &lt;thead&gt;
                      &lt;tr style="font-weight: bold; text-decoration: underline;"&gt;
                          &lt;th align="center" style="width: 40px;"&gt;REF#&lt;/th&gt;
                          &lt;th align="center" style="width: 75px;"&gt;PO#&lt;/th&gt;
                          &lt;th align="center" style="width: 75px;"&gt;PRO#&lt;/th&gt;
                          &lt;th align="left" style="width: 125px;"&gt;CONSIGNEE ADDRESS&lt;/th&gt;
                          &lt;th align="center" style="width: 125px;"&gt;SPECIAL INST&lt;/th&gt;
                          &lt;th align="center" style="width: 100px;"&gt;COMMODITY&lt;/th&gt;                 
                          &lt;th align="center" style="width: 40px;"&gt;NMFC#&lt;/th&gt;
                          &lt;th align="center" style="width: 30px;"&gt;SUB&lt;/th&gt;
                          &lt;th align="center" style="width: 40px;"&gt;CLASS&lt;/th&gt;
                          &lt;th align="center" style="width: 40px;"&gt;UNITS&lt;/th&gt;
                          &lt;th align="center" style="width: 30px;"&gt;PKGS&lt;/th&gt;
                          &lt;th align="RIGHT" style="width: 40px;"&gt;WEIGHT&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      '.$tablerows.'
                  &lt;/tbody&gt;
              &lt;/table&gt;
          ';
      $tableData = '
              &lt;style&gt;
                  table#manifestTable tr.odd td{
                      background-color: #F0F0F0;
                  }
                  div.totalDIV{
                      vertical-align: bottom;
                      font-weight: bold;
                  }
              &lt;/style&gt;
              &lt;table id="manifestTable" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 8pt;"&gt;
                  &lt;thead&gt;
                      &lt;tr style="font-weight: bold; text-decoration: underline;"&gt;
                          &lt;th align="center" style="width: 40px;"&gt;REF#&lt;/th&gt;
                          &lt;th align="center" style="width: 75px;"&gt;PO#&lt;/th&gt;
                          &lt;th align="center" style="width: 75px;"&gt;PRO#&lt;/th&gt;
                          &lt;th align="left" style="width: 125px;"&gt;CONSIGNEE ADDRESS&lt;/th&gt;
                          &lt;th align="center" style="width: 125px;"&gt;SPECIAL INST&lt;/th&gt;
                          &lt;th align="center" style="width: 100px;"&gt;COMMODITY&lt;/th&gt;                 
                          &lt;th align="center" style="width: 40px;"&gt;NMFC#&lt;/th&gt;
                          &lt;th align="center" style="width: 30px;"&gt;SUB&lt;/th&gt;
                          &lt;th align="center" style="width: 40px;"&gt;CLASS&lt;/th&gt;
                          &lt;th align="center" style="width: 40px;"&gt;UNITS&lt;/th&gt;
                          &lt;th align="center" style="width: 30px;"&gt;PKGS&lt;/th&gt;
                          &lt;th align="RIGHT" style="width: 40px;"&gt;WEIGHT&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      '.$tablerows1.'
                  &lt;/tbody&gt;
              &lt;/table&gt;
          ';
      $tableData = '
              &lt;style&gt;
                  table#manifestTable tr.odd td{
                      background-color: #F0F0F0;
                  }
                  div.totalDIV{
                      vertical-align: bottom;
                      font-weight: bold;
                  }
              &lt;/style&gt;
              &lt;table id="manifestTable" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 8pt;"&gt;
                  &lt;thead&gt;
                      &lt;tr style="font-weight: bold; text-decoration: underline;"&gt;
                          &lt;th align="center" style="width: 40px;"&gt;REF#&lt;/th&gt;
                          &lt;th align="center" style="width: 75px;"&gt;PO#&lt;/th&gt;
                          &lt;th align="center" style="width: 75px;"&gt;PRO#&lt;/th&gt;
                          &lt;th align="left" style="width: 125px;"&gt;CONSIGNEE ADDRESS&lt;/th&gt;
                          &lt;th align="center" style="width: 125px;"&gt;SPECIAL INST&lt;/th&gt;
                          &lt;th align="center" style="width: 100px;"&gt;COMMODITY&lt;/th&gt;                 
                          &lt;th align="center" style="width: 40px;"&gt;NMFC#&lt;/th&gt;
                          &lt;th align="center" style="width: 30px;"&gt;SUB&lt;/th&gt;
                          &lt;th align="center" style="width: 40px;"&gt;CLASS&lt;/th&gt;
                          &lt;th align="center" style="width: 40px;"&gt;UNITS&lt;/th&gt;
                          &lt;th align="center" style="width: 30px;"&gt;PKGS&lt;/th&gt;
                          &lt;th align="RIGHT" style="width: 40px;"&gt;WEIGHT&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      '.$tablerows2.'
                  &lt;/tbody&gt;
              &lt;/table&gt;
          ';
  
      $shipperCarierData ='
              &lt;table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 10pt;"&gt;
                  &lt;tr&gt;
                      &lt;td width="35%" align="left" valign="top" style="padding-left: 25px;"&gt;
                          &lt;table width="250" border="0" cellpadding="0" cellspacing="0"&gt;
                              &lt;tr&gt;
                                  &lt;td align="left" valign="top" width="55"&gt;Shipper:&lt;/td&gt;
                                  &lt;td align="left" valign="top"&gt;
                                      company name&lt;br /&gt;
                                      9000 dummy street&lt;br /&gt;
                                      town, usa 01234&lt;br /&gt;
                                      Jon doe (123) 456-7890
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/td&gt;
                          &lt;td align="left" valign="top" width="45"&gt;&lt;strong&gt;Bill To:&lt;/strong&gt;&lt;/td&gt;
                          &lt;td width="25%" align="left" valign="top"&gt;
  
                              EST&lt;br/&gt;
                              4444 street name&lt;br/&gt;
                              dummy town, 10004&lt;br/&gt;
                              &lt;br/&gt;
  
                      &lt;/td&gt;               
                      &lt;td align="left" valign="top" width="250"&gt;
                          &lt;strong&gt;Carrier:&lt;/strong&gt; '.$row['shipper'].'&lt;br /&gt;
                          &lt;strong&gt;Trailer#:&lt;/strong&gt; '.$row['trailer'].'&lt;br /&gt;
                          &lt;strong&gt;Service:&lt;/strong&gt; Standard-Bill Accessorial Code WGST&lt;br /&gt;
                          &lt;strong&gt;Terms:&lt;/strong&gt; Prepaid
                      &lt;/td&gt;
  
  
                  &lt;/tr&gt;
              &lt;/table&gt;
          ';
      $shipperCarierData1 ='
              &lt;table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 10pt;"&gt;
                  &lt;tr&gt;
                      &lt;td width="35%" align="left" valign="top" style="padding-left: 25px;"&gt;
                          &lt;table width="250" border="0" cellpadding="0" cellspacing="0"&gt;
                              &lt;tr&gt;
                                  &lt;td align="left" valign="top" width="55"&gt;Shipper:&lt;/td&gt;
                                  &lt;td align="left" valign="top"&gt;
                                      company name 2&lt;br /&gt;
                                      9000 dummy street&lt;br /&gt;
                                      town, usa 01234&lt;br /&gt;
                                      Jon doe (123) 456-7890
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/td&gt;
                          &lt;td align="left" valign="top" width="45"&gt;&lt;strong&gt;Bill To:&lt;/strong&gt;&lt;/td&gt;
                          &lt;td width="25%" align="left" valign="top"&gt;
  
                              EST&lt;br/&gt;
                              4444 street name&lt;br/&gt;
                              dummy town, 10004&lt;br/&gt;
                              &lt;br/&gt;
  
                      &lt;/td&gt;               
                      &lt;td align="left" valign="top" width="250"&gt;
                          &lt;strong&gt;Carrier:&lt;/strong&gt; '.$row['shipper'].'&lt;br /&gt;
                          &lt;strong&gt;Trailer#:&lt;/strong&gt; '.$row['trailer'].'&lt;br /&gt;
                          &lt;strong&gt;Service:&lt;/strong&gt; Standard-Bill Accessorial Code WGST&lt;br /&gt;
                          &lt;strong&gt;Terms:&lt;/strong&gt; Prepaid
                      &lt;/td&gt;
  
  
                  &lt;/tr&gt;
              &lt;/table&gt;
          ';
      $shipperCarierData2 ='
              &lt;table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 10pt;"&gt;
                  &lt;tr&gt;
                      &lt;td width="35%" align="left" valign="top" style="padding-left: 25px;"&gt;
                          &lt;table width="250" border="0" cellpadding="0" cellspacing="0"&gt;
                              &lt;tr&gt;
                                  &lt;td align="left" valign="top" width="55"&gt;Shipper:&lt;/td&gt;
                                  &lt;td align="left" valign="top"&gt;
                                      company name&lt;br /&gt;
                                      9000 dummy street&lt;br /&gt;
                                      town, usa 01234&lt;br /&gt;
                                      Jon doe (123) 456-7890
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/td&gt;
  
  
                      &lt;td align="left" valign="top" width="250"&gt;
                          &lt;strong&gt;Carrier:&lt;/strong&gt; '.$row['shipper'].'&lt;br /&gt;
                          &lt;strong&gt;Trailer#:&lt;/strong&gt; '.$row['trailer'].'&lt;br /&gt;
                          &lt;strong&gt;Service:&lt;/strong&gt; Standard-Bill Accessorial Code WGST&lt;br /&gt;
                          &lt;strong&gt;Terms:&lt;/strong&gt; Prepaid
                      &lt;/td&gt;
  
  
                  &lt;/tr&gt;
              &lt;/table&gt;
          ';
  </code></pre>
  
  <p>This is the pdf creation using TCPDF. I am trying to use a foreach to create a new pdf for each customer. I realize that does not work.</p>
  
  <pre><code>if(!empty($tablerows)) {
      $pdf-&gt;startPageGroup();
      $pdf-&gt;SetPrintFooter(false);
      $pdf-&gt;AddPage();
      $pdf-&gt;writeHTMLCell(280, 0, 5, 15, $shipperCarierData, 0, 0, false, true, 'C', true);
      $pdf-&gt;writeHTMLCell(280, 0, 3, 35, $tableData, 0, 0, false, true, 'C', true);
  
      $pdf-&gt;AddPage();
  
      $pdf-&gt;writeHTMLCell(280, 0, 5, 160, $disclaimerHTML, 0, 0, false, true, 'C', true);
  
  
      $pdf-&gt;SetPrintFooter(true);
  }
  if(!empty($tablerows1)) {
      $pdf-&gt;startPageGroup();
      $pdf-&gt;SetPrintFooter(false);
      $pdf-&gt;AddPage();
  
      $pdf-&gt;writeHTMLCell(280, 0, 5, 15, $shipperCarierData1, 0, 0, false, true, 'C', true);
  #WRITE TABLE ROWS
      $pdf-&gt;writeHTMLCell(280, 0, 3, 35, $tableData1, 0, 0, false, true, 'C', true);
  
  
  
  
      $pdf-&gt;lastPage();
  //$pdf-&gt;writeHTMLCell(280, 0, 5, 160, $disclaimerHTML, 0, 0, false, true, 'C', true);
      $pdf-&gt;AddPage();
  
      $pdf-&gt;writeHTMLCell(280, 0, 5, 160, $disclaimerHTML, 0, 0, false, true, 'C', true);
  
  }
  foreach($row['customer'] as $cus) {
      if (!empty($tablerows2)) {
          $pdf-&gt;startPageGroup();
          $pdf-&gt;SetPrintFooter(false);
          $pdf-&gt;AddPage();
  
          $pdf-&gt;writeHTMLCell(280, 0, 5, 15, $shipperCarierData2, 0, 0, false, true, 'C', true);
  #WRITE TABLE ROWS
          $pdf-&gt;writeHTMLCell(280, 0, 3, 35, $tableData2, 0, 0, false, true, 'C', true);
  
  
  
  
          $pdf-&gt;lastPage();
  
          $pdf-&gt;AddPage();
  
          $pdf-&gt;writeHTMLCell(280, 0, 5, 160, $disclaimerHTML, 0, 0, false, true, 'C', true);
      }
  }
  //Close and output PDF document
  $pdf-&gt;Output('print_manifest.pdf', 'I');
  </code></pre>