title: Formating Multiple Tables While Using Herdoc
body: <p>Thank you in advance for checking out my post. I'll try to get straight to the details</p>
  
  <p>Background: I'm trying to pull quote, lead, and order data from SQL and display that in multiple tables using PHP's heredoc. Each query has two tables for it, By Rep and By Territory. </p>
  
  <p>What I'm trying to do: I want to display the tables with an identifying header, a line underneath the header, side by side, then display the next set of tables in a row underneath that one. </p>
  
  <p>The Problem: When I put the Header where I think it should go in the code (in the heredoc in the second set of tables table1) it completely throws all of my formattings out the window and displays in a strange way.(see screenshot) </p>
  
  <p>I'm pretty new to PHP and have almost no experience with CSS or HTML, as you'll be able to tell from the following code, help and an explanation why it doesn't work that way would be greatly appreciated. I have copied the second set of tables from the first bit of code to illustrate the problem I'm having, it will eventually change.  I'm sure it's a stupid mistake, so please be kind upon my noob soul. Bellow is the code and a screenshot of what it looks like.
  <a href="https://i.stack.imgur.com/q4GN9.jpg" rel="nofollow noreferrer">ScreenShot</a> </p>
  
  <pre><code>&lt;style rel="stylesheet" type="text/css"&gt;
  
  caption{
      font-size:30px; 
      font-weight: bold; 
      text-align:center;
  }
  
  .table1 {
      width=80%;
      float:left;
      margin-left:120px;
  
  }
  
  
  .table2 {
      width=45%;
      float:right;
      margin-right:700px;
  
  }
  
  &lt;/style&gt;
  
  
  
  
  
  &lt;?php
  
  /**
   * Finds the amount of quotes generated by a specific territory 
   * 
   *
   * @author Trevor-Prosales  11/05/2018
   * 
   *  *
    */
  
  //Search by date bar
  print "&lt;h3&gt;All Quotes Report&lt;/h3&gt;";
  
  //sets date
  if (!strlen($end_date)){
      $end_date = date("Y-m-d");
  }
  
  if ( strtotime($end_date)==-1||strtotime($end_date)===false ){
      $end_date = date("Y-m-d");
  }
  
  $end_date = make_display_date($end_date);
  
  //adds the text field to search
  $form = &lt;&lt;&lt;__THIS
  &lt;form method=post action="" name="dateForm"&gt;
  Most recent date to show: &lt;input type="text" name="end_date" value="$end_date"&gt;
  &lt;input type="hidden" name="dateForm_submitted" value="1"&gt;
  &lt;input type="hidden" name="orderby" value="quote_num"&gt;
  &lt;input type="hidden" name="sortorder" value="desc"&gt;
  &lt;input type="submit" value="View Quotes"&gt;
  &lt;/form&gt;
  &lt;br /&gt;
  __THIS;
  
  print $form;
  
  
  
  
  
  
  //first set of tables
  if ($dateForm_submitted || ($QuoteForm_submitted &amp;&amp; $deleteOrders==0))
  {
  
      //day,week,month,year,twoyear
      $db_end_date  = date("Y-m-d",strtotime($end_date));
      $db_end_date1 = date("Y-m-d",strtotime($end_date) - 86400);
      $db_end_date2 = date("Y-m-d",strtotime($end_date) - 604800);
      $db_end_date3 = date("Y-m-d",strtotime($end_date) - 60*60*24*30);
      $db_end_date4 = date("Y-m-d",strtotime($end_date) - 60*60*24*30*12);
      $db_end_date5 = date("Y-m-d",strtotime($end_date) - 60*60*24*30*24);
  
  
      //First Table
      if (!strlen($orderby)) $orderby="rep2";
      if (!strlen($sortorder)) $sortorder="desc";
  
  
      $sql = "Select rep2,
  
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date1 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Daily,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date2 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Weekly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date3 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Monthly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date4 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Yearly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date5 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) 2Yearly
  
      FROM so_orders
      WHERE rep2 = '401' OR rep2= '399' OR rep2= '142' OR rep2= '332'
      GROUP BY rep2 ORDER BY $orderby $sortorder";        
  
  
      $res=db_query($sql);
      $num_rows = db_num_rows($res);
  
  
      if (! $num_rows )
          kill(getErrorMessage(161));
  
  
  
      print &lt;&lt;&lt;__THAT
  &lt;h1 &gt;Number of Quotes Entered:&lt;hr&gt;&lt;/h1&gt;
  &lt;form method=post action="" name="QuoteForm"&gt;
  &lt;input type="hidden" name="orderby" value="$orderby"&gt;
  &lt;input type="hidden" name="sortorder" value="$sortorder"&gt;
  &lt;input type="hidden" name="QuoteForm_submitted" value="1"&gt;
  
  &lt;table  class="table1" frame="box" cellspacing=0 cellpadding=0&gt;
  &lt;caption&gt;By Territory&lt;/caption&gt;
      &lt;tr  class=rowcolor&gt;
          &lt;td class=cellborderbt&gt;Sales Rep&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Daily&lt;/td&gt;
          &lt;td class=cellborderbt nowrap&gt;Weekly&lt;/td&gt;
          &lt;td class=cellborderbt nowrap&gt;Monthly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Yearly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;2 Year&lt;/td&gt;
              &lt;/tr&gt;
  __THAT;
  
  
  
  
      while($data=db_fetch_array($res) )
      {
          $rowClass = ($rowClass=="roweven")?"rowodd":"roweven";
          $quote_date = make_display_date($data['quote_date']);
  
  
          print &lt;&lt;&lt;__THIS
      &lt;tr class="{$rowClass}"&gt;
          &lt;td&gt;{$data['rep2']}&lt;/td&gt;
          &lt;td&gt;{$data['Daily']}&lt;/td&gt;
          &lt;td&gt;{$data['Weekly']}&lt;/td&gt;
          &lt;td&gt;{$data['Monthly']}&lt;/td&gt;
          &lt;td&gt;{$data['Yearly']}&lt;/td&gt;
          &lt;td&gt;{$data['2Yearly']}&lt;/td&gt;
      &lt;/tr&gt;
  
  __THIS;
  
  
  
      }
  
  
     print &lt;&lt;&lt; __THIS
  &lt;/table&gt;
  __THIS;
  
  
  
  
  
          //second table
          if (!strlen($orderby)) $orderby="rep1";
      if (!strlen($sortorder)) $sortorder="desc";
  
  
  
      $sql2 = "Select rep1,
  
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date1 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) Daily,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date2 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Weekly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date3 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) Monthly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date4 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Yearly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date5 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) 2Yearly
  
  
      FROM so_orders
      WHERE rep1 = '231' OR rep1= '339' OR rep1= '401' OR rep1= '399' OR rep1= '142' OR rep1= '332' OR rep1 ='414'
      GROUP BY rep1 ORDER BY $orderby $sortorder";        
  
  
      $res2=db_query($sql2);
      $num_rows2 = db_num_rows($res2);
  
  
      if (! $num_rows )
          kill(getErrorMessage(161));
  
  
      print &lt;&lt;&lt;__THIS
  &lt;form method=post action="" name="QuoteForm"&gt;
  &lt;input type="hidden" name="orderby" value="$orderby"&gt;
  &lt;input type="hidden" name="sortorder" value="$sortorder"&gt;
  &lt;input type="hidden" name="QuoteForm_submitted" value="1"&gt;
  
  &lt;table class="table2"  frame="box" cellspacing=0 cellpadding=0&gt;
  &lt;caption&gt;By Rep&lt;/caption&gt;
      &lt;tr  class=rowcolor&gt;
          &lt;td class=cellborderbt&gt;Sales Rep&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Daily&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Weekly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Monthly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Yearly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;2 Year&lt;/td&gt;
              &lt;/tr&gt;
  __THIS;
  
  
      while($data=db_fetch_array($res2) )
      {
          $rowClass = ($rowClass=="roweven")?"rowodd":"roweven";
          $quote_date = make_display_date($data['quote_date']);
  
  
  
          print &lt;&lt;&lt;__THIS
      &lt;tr class="{$rowClass}"&gt;
          &lt;td&gt;{$data['rep1']}&lt;/td&gt;
          &lt;td&gt;{$data['Daily']}&lt;/td&gt;
          &lt;td&gt;{$data['Weekly']}&lt;/td&gt;
          &lt;td&gt;{$data['Monthly']}&lt;/td&gt;
          &lt;td&gt;{$data['Yearly']}&lt;/td&gt;
          &lt;td&gt;{$data['2Yearly']}&lt;/td&gt;
  
              &lt;/tr&gt;
  __THIS;
  
  
      }
  
  
     print &lt;&lt;&lt; __THIS
  &lt;/table&gt;
  __THIS;
  
  }  //end of if statement
  
  
  
  
  
  
  /**
  //second set of tables
  //*
  //*
  */
  
  if ($dateForm_submitted || ($QuoteForm_submitted &amp;&amp; $deleteOrders==0))
  {
  
      $db_end_date  = date("Y-m-d",strtotime($end_date));
      $db_end_date1 = date("Y-m-d",strtotime($end_date) - 86400);
      $db_end_date2 = date("Y-m-d",strtotime($end_date) - 604800);
      $db_end_date3 = date("Y-m-d",strtotime($end_date) - 60*60*24*30);
      $db_end_date4 = date("Y-m-d",strtotime($end_date) - 60*60*24*30*12);
      $db_end_date5 = date("Y-m-d",strtotime($end_date) - 60*60*24*30*24);
  
  
      //First Table
      if (!strlen($orderby)) $orderby="rep2";
      if (!strlen($sortorder)) $sortorder="desc";
  
  
      $sql = "Select rep2,
  
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date1 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) Daily,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date2 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Weekly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date3 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) Monthly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date4 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Yearly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date5 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) 2Yearly
  
      FROM so_orders
      WHERE rep2 = '401' OR rep2= '399' OR rep2= '142' OR rep2= '332'
      GROUP BY rep2 ORDER BY $orderby $sortorder";        
  
  
      $res=db_query($sql);
      $num_rows = db_num_rows($res);
  
  
      if (! $num_rows )
          kill(getErrorMessage(161));
  
  
      print &lt;&lt;&lt;__THAT
  &lt;h1 &gt;Number of Leads Entered:&lt;hr&gt;&lt;/h1&gt;
  &lt;form method=post action="" name="QuoteForm"&gt;
  &lt;input type="hidden" name="orderby" value="$orderby"&gt;
  &lt;input type="hidden" name="sortorder" value="$sortorder"&gt;
  &lt;input type="hidden" name="QuoteForm_submitted" value="1"&gt;
  
  &lt;table  class="table2" frame="box" cellspacing=0 cellpadding=0&gt;
  &lt;caption&gt;By Territory2&lt;/caption&gt;
      &lt;tr  class=rowcolor&gt;
          &lt;td class=cellborderbt&gt;Sales Rep&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Daily&lt;/td&gt;
          &lt;td class=cellborderbt nowrap&gt;Weekly&lt;/td&gt;
          &lt;td class=cellborderbt nowrap&gt;Monthly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Yearly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;2 Year&lt;/td&gt;
              &lt;/tr&gt;
  __THAT;
  
  
  
  
      while($data=db_fetch_array($res) )
      {
          $rowClass = ($rowClass=="roweven")?"rowodd":"roweven";
          $quote_date = make_display_date($data['quote_date']);
  
  
          print &lt;&lt;&lt;__THIS
      &lt;tr class="{$rowClass}"&gt;
          &lt;td&gt;{$data['rep2']}&lt;/td&gt;
          &lt;td&gt;{$data['Daily']}&lt;/td&gt;
          &lt;td&gt;{$data['Weekly']}&lt;/td&gt;
          &lt;td&gt;{$data['Monthly']}&lt;/td&gt;
          &lt;td&gt;{$data['Yearly']}&lt;/td&gt;
          &lt;td&gt;{$data['2Yearly']}&lt;/td&gt;
  
              &lt;/tr&gt;
  
  __THIS;
  
  
  
      }
  
  
  
     print &lt;&lt;&lt; __THIS
  &lt;/table&gt;
  __THIS;
  
  
  
          //second table
          if (!strlen($orderby)) $orderby="rep1";
      if (!strlen($sortorder)) $sortorder="desc";
  
  
  
      $sql2 = "Select rep1,
  
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date1 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) Daily,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date2 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Weekly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date3 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) Monthly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date4 . "' And '".$db_end_date."'   THEN 1 ELSE 0  END) Yearly,
              SUM(CASE    When quote_date BETWEEN '" .$db_end_date5 . "' And '".$db_end_date."'   THEN 1 ELSE 0 END) 2Yearly
  
  
      FROM so_orders
      WHERE rep1 = '231' OR rep1= '339' OR rep1= '401' OR rep1= '399' OR rep1= '142' OR rep1= '332' OR rep1 ='414'
      GROUP BY rep1 ORDER BY $orderby $sortorder";        
  
  
      $res2=db_query($sql2);
      $num_rows2 = db_num_rows($res2);
  
  
      if (! $num_rows )
          kill(getErrorMessage(161));
  
  
      print &lt;&lt;&lt;__THIS
  &lt;form method=post action="" name="QuoteForm"&gt;
  &lt;input type="hidden" name="orderby" value="$orderby"&gt;
  &lt;input type="hidden" name="sortorder" value="$sortorder"&gt;
  &lt;input type="hidden" name="QuoteForm_submitted" value="1"&gt;
  
  &lt;table class="table1"  frame="box" cellspacing=0 cellpadding=0&gt;
  &lt;caption&gt;By Rep2&lt;/caption&gt;
      &lt;tr  class=rowcolor&gt;
          &lt;td class=cellborderbt&gt;Sales Rep&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Daily&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Weekly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Monthly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;Yearly&lt;/td&gt;
          &lt;td class=cellborderbt&gt;2 Year&lt;/td&gt;
              &lt;/tr&gt;
  __THIS;
  
  
      while($data=db_fetch_array($res2) )
      {
          $rowClass = ($rowClass=="roweven")?"rowodd":"roweven";
          $quote_date = make_display_date($data['quote_date']);
  
  
          print &lt;&lt;&lt;__THIS
      &lt;tr class="{$rowClass}"&gt;
          &lt;td&gt;{$data['rep1']}&lt;/td&gt;
          &lt;td&gt;{$data['Daily']}&lt;/td&gt;
          &lt;td&gt;{$data['Weekly']}&lt;/td&gt;
          &lt;td&gt;{$data['Monthly']}&lt;/td&gt;
          &lt;td&gt;{$data['Yearly']}&lt;/td&gt;
          &lt;td&gt;{$data['2Yearly']}&lt;/td&gt;
  
              &lt;/tr&gt;
  __THIS;
  
  
      }
  
  
     print &lt;&lt;&lt; __THIS
  &lt;/table&gt;
  __THIS;
  
  
  } 
  
  ?&gt;
  </code></pre>