如何使用PHP将行附加到tcpdf中的表?

时间:2018-06-08 19:12:42

标签: php html tcpdf

我有以下表格,其中有一个金额输入,在提交时应该存储在数据库中,并且应该附加到使用TCPDF形成的pdf中的表格行。我应该如何在TCPDF中附加行?

以下是我的HTML代码:

<div class="form-group">
<label class="col-sm-3 control-label" for="amount">Amount</label>
<div class="col-sm-9">
<input type="number" class="form-control"  name="amount" id="amount"  
placeholder="Amount">
</div>
</div>          
<div class="form-group">
<div class="col-sm-2">

<button type="submit" class="btn btn-success" id="pay-now" name="pay- 
now">Pay Now</button>

                                  </div>
                                </div>

以下是我的PHP代码:

 <?php 
       if(isset($_POST["pdf"]))  
         {  
           require_once('tcpdf/tcpdf.php');  
           $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', 
           false);  
           $obj_pdf->SetCreator(PDF_CREATOR);   
           $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', 
           PDF_FONT_SIZE_MAIN));  
           $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', 
           PDF_FONT_SIZE_DATA));  
           $obj_pdf->SetDefaultMonospacedFont('helvetica');  
           $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);  
           $obj_pdf->SetMargins(PDF_MARGIN_LEFT, '4', PDF_MARGIN_RIGHT);  
           $obj_pdf->setPrintHeader(false);  
           $obj_pdf->setPrintFooter(false);  
           $obj_pdf->SetAutoPageBreak(TRUE, 10);  
           $obj_pdf->SetFont('helvetica', '', 12);  
           $obj_pdf->AddPage(); 
          $sql = "SELECT * FROM donors WHERE user_name='$username'";
          $result = mysqli_query($conn, $sql);
          $html = '';
          $html .= '


       <!doctype html>
         <html lang="en">
          <head>

            <style>
                   .text-center{
                          text-align: center;
                               }

                  .img-fluid{

                    width: 200px;
                    height: 41px;
                           }

                 .title{

                text-decoration: underline;
                        }

              .text-left{

                  text-align: left;
                        }


                 </style>

          </head>
               <body>
               <div >
              <div class="text-center">
              <div >
                <img src="img/logo.png" class="img-fluid">
            </div>
            <div class="title">
                <h1>Donation Report</h1>
            </div>
            <div >
                <h3 >';
              $html .= "Date : " . date("m-d-Y"); 
              $html .= '</h3>
            </div>
            <div class="text-left">
                <h4>Hello ';
               $html .= $_SESSION['u_user_name'];

                 $html .= ',</h4>
                <p>Thanks a lot for donating and supporting us. Please find your 
                details below for tax filing:</p>
            </div>

            <div>
                <table border="1" cellspacing="0" cellpadding="5" id="box">
                    <tr>
                        <td>Date</td>
                        <td>Amount</td>

                    </tr><tr><td>';

                  $html .= date("m-d-Y");

               $html .= '</td><td>';

                while($row = mysqli_fetch_assoc($result)){


              $html .= $row["total_donation_amount"];

        $html .= '</td></tr></table>
            </div>

            <div class=" text-left">
                <h4>Thanks and Regards,</h4>
                <h4>Detroit Pheonix Center</h4>
                <h4>Detroit, Mi</h4>

            </div>

             </div>

            </div>

           </body>
            </html>';


           $obj_pdf->writeHTML($html); 



            $obj_pdf->Output('donor_report.pdf', 'D');}
             ?>

这里当我点击html表单中的paynow按钮时,它应该存储在数据库中,每当我使用paynow付款时应该添加一行,并且应该在pdf上显示。当我按pdf按钮时会出现pdf。这段代码中没有提到。

0 个答案:

没有答案