title: How to filter a table then the output to be printed in a pdf
body: <p>Hi guys I am trying to filter a table then print the filtered table to a pdf.</p>
  
  <p>I typed other codes but this is as close as i can get to finishing it.</p>
  
  <p>I tried different solutions but cant seem to fix it.</p>
  
  <p>If you guys have any suggestions on how to do it just say. Any help would be great.</p>
  
  <p>Help guys! Thanks in advance!</p>
  
  <p>This is reportss.php</p>
  
  <pre><code>&lt;?php 
  ob_start(); 
  include ('filters.php');
    function fetch_data()  
    {  
    require('filters.php');
    $output = '';  
    $conn = mysqli_connect("localhost", "root", "", "trans");  
    $sql = "SELECT * FROM customers ORDER BY created_at ASC";  
    $result = mysqli_query($conn, $sql);  
    while($row = mysqli_fetch_array($result))  
    {       
    $output .= '&lt;tr&gt;  
                        &lt;td&gt;'.$row["id"].'&lt;/td&gt;  
                        &lt;td&gt;'.$row["first_name"].'&lt;/td&gt;  
                        &lt;td&gt;'.$row["last_name"].'&lt;/td&gt;  
                         &lt;td&gt;'.$row["email"].'&lt;/td&gt;  
                        &lt;td&gt;'.$row["created_at"].'&lt;/td&gt;  
                   &lt;/tr&gt;  
                        ';  
    }  
    return $output;  
    }    if(isset($_POST["generate_pdf"]))  
   {  
    require_once('tcpdf/tcpdf.php');  
    $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', 
    false);  
    $obj_pdf-&gt;SetCreator(PDF_CREATOR);  
    $obj_pdf-&gt;SetTitle("Customer Transactions Report");  
    $obj_pdf-&gt;SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);  
    $obj_pdf-&gt;setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', 
    PDF_FONT_SIZE_MAIN));  
    $obj_pdf-&gt;setFooterFont(Array(PDF_FONT_NAME_DATA, '', 
    PDF_FONT_SIZE_DATA));  
    $obj_pdf-&gt;SetDefaultMonospacedFont('helvetica');  
    $obj_pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);  
    $obj_pdf-&gt;SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);  
    $obj_pdf-&gt;setPrintHeader(false);  
    $obj_pdf-&gt;setPrintFooter(false);  
    $obj_pdf-&gt;SetAutoPageBreak(TRUE, 10);  
    $obj_pdf-&gt;SetFont('helvetica', '', 11);  
    $obj_pdf-&gt;AddPage();  
    $content = '';  
    $content .= '  
    &lt;h4 align="center"&gt;Customer Transactions Report for Viaje&lt;/h4&gt;&lt;br /&gt; 
    &lt;table border="1" cellspacing="0" cellpadding="3"&gt;  
         &lt;tr&gt;  
              &lt;th width="26%"&gt;ID&lt;/th&gt;  
              &lt;th width="15%"&gt;First Name&lt;/th&gt;  
              &lt;th width="15%"&gt;Last Name&lt;/th&gt;  
              &lt;th width="33%"&gt;Email&lt;/th&gt;  
              &lt;th width="13%"&gt;Order Date&lt;/th&gt;  
         &lt;/tr&gt;  
    ';  
    $content .= fetch_data();  
    $content .= '&lt;/table&gt;';  
    $obj_pdf-&gt;writeHTML($content);  
    $obj_pdf-&gt;Output('file.pdf', 'I');  
    exit();
  
   }  
   ?&gt;  
   &lt;!DOCTYPE html&gt;  
   &lt;html&gt;  
    &lt;head&gt;  
  
         &lt;script 
  src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"&gt;&lt;/script&gt;  
         &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /&gt;  
         &lt;script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"&gt;&lt;/script&gt;  
         &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"&gt;  
    &lt;/head&gt;  
    &lt;body&gt;  
         &lt;br /&gt;&lt;br /&gt;  
  
         &lt;div class="container" style="width:900px;"&gt;  
              &lt;h2 align="center"&gt;Showings Customer Transactions&lt;/h2&gt;  &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;BR&gt;&lt;BR&gt;
  
              &lt;div class="col-md-3"&gt;  
                   &lt;input type="text" name="from_date" id="from_date" class="form-control" placeholder="From Date" /&gt;  
              &lt;/div&gt;  
              &lt;div class="col-md-3"&gt;  
                   &lt;input type="text" name="to_date" id="to_date" class="form-control" placeholder="To Date" /&gt;  
              &lt;/div&gt;  
              &lt;div class="col-md-5"&gt;  
                  &lt;form method="post"&gt;  
                    &lt;input type="button" name="filter" id="filter" value="Filter" class="btn btn-info" /&gt;  
  
                    &lt;input type="submit" name="generate_pdf" class="btn btn-success" value="Print" /&gt;  
                  &lt;/form&gt;
              &lt;/div&gt;  
              &lt;div style="clear:both"&gt;&lt;/div&gt;                 
              &lt;br /&gt;  
              &lt;div id="order_table"&gt;  
  
                   &lt;table class="table table-bordered"&gt;  
                        &lt;tr&gt;  
                             &lt;th width="5%" &gt;ID&lt;/th&gt;  
                             &lt;th width="30%" &gt;First Name&lt;/th&gt;  
                             &lt;th width="43%" &gt;Last Name&lt;/th&gt;  
                             &lt;th width="10%" &gt;Email&lt;/th&gt;  
                             &lt;th width="12%" &gt;Order Date&lt;/th&gt;  
                        &lt;/tr&gt;
                  &lt;?php  
                   echo fetch_data();  
                   ?&gt;  
  
  
  
                   &lt;/table&gt;  
  
              &lt;/div&gt;  
         &lt;/div&gt;  
  
    &lt;/body&gt;  
  
    &lt;script&gt;  
    $(document).ready(function(){  
         $.datepicker.setDefaults({  
              dateFormat: 'yy-mm-dd'   
         });  
         $(function(){  
              $("#from_date").datepicker();  
              $("#to_date").datepicker();  
         });  
         $('#filter').click(function(){  
              var from_date = $('#from_date').val();  
              var to_date = $('#to_date').val();  
              if(from_date != '' &amp;&amp; to_date != '')  
              {  
                   $.ajax({  
                        url:"filters.php",  
                        method:"POST",  
                        data:{from_date:from_date, to_date:to_date},  
                        success:function(data)  
                        {  
                             $( '#order_table').html(data);  
                        }  
                   });  
              }  
              else  
              {  
                   alert("Please Select Date");  
              }  
         });  
    });  
  </code></pre>
  
  <p></p>
  
  <p>
     </p>
  
  <p>This is filters.php</p>
  
  <pre><code> &lt;?php  
  
   if(isset($_POST["from_date"], $_POST["to_date"]))  
   {  
    $connect = mysqli_connect("localhost", "root", "", "trans");  
    $output = '';  
  
    $query = "  
         SELECT * FROM customers  
         WHERE cast(created_at as date) BETWEEN '".$_POST["from_date"]."'  AND 
    '".$_POST["to_date"]."'  
    ";  
  
    $result = mysqli_query($connect, $query);  
    $output .= '  
         &lt;table class="table table-bordered"&gt;  
              &lt;tr&gt;  
                   &lt;th width="5%"&gt;ID&lt;/th&gt;  
                   &lt;th width="30%"&gt;First Name&lt;/th&gt;  
                   &lt;th width="43%"&gt;Last Name&lt;/th&gt;  
                   &lt;th width="10%"&gt;Email&lt;/th&gt;  
                   &lt;th width="12%"&gt;Order Date&lt;/th&gt;  
              &lt;/tr&gt;  
    ';  
    if(mysqli_num_rows($result) &gt; 0)  
    {  
         while($row = mysqli_fetch_array($result))  
         {  
              $output .= '  
                   &lt;tr&gt;  
                        &lt;td&gt;'. $row["id"] .'&lt;/td&gt;  
                        &lt;td&gt;'. $row["first_name"] .'&lt;/td&gt;  
                        &lt;td&gt;'. $row["last_name"] .'&lt;/td&gt;  
                        &lt;td&gt;$ '. $row["email"] .'&lt;/td&gt;  
                        &lt;td&gt;'. $row["created_at"] .'&lt;/td&gt;  
                   &lt;/tr&gt;  
              ';  
         }  
    }  
    else  
    {  
         $output .= '  
              &lt;tr&gt;  
                   &lt;td colspan="5"&gt;No Order Found&lt;/td&gt;  
              &lt;/tr&gt;  
         ';  
    }  
    $output .= '&lt;/table&gt;';  
    echo $output;  
   }  
   ?&gt;
  </code></pre>