繁体   English   中英

TCPDF如何在HTML里面写PHP代码

[英]TCPDF how to write the PHP code inside the HTML

我正在使用 TCPDF 创建库存清单打印。 我在将 while 循环放入 HTML 标签时遇到了一个问题,它出错了,我该如何正确编写它。 我尝试过所以我写在下面。 日期和lastinserted和grandtotal工资余额都显示得很好。 只有我需要while循环我试过很多次但我不能

<?php
require_once('lib/master/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, [80, 230], true, 'UTF-8', false);

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetFont('dejavusans', '', 10);
$pdf->AddPage();
include("db.php");
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $last_insert_id = 51;
    $sql = "select i.sales_id,i.product_id,i.sell_price,i.qty,i.discount,i.total,s.date,s.grand_total,s.pay,s.balance,pr.p_name from sales_product i, sales s,product pr where s.id = i.sales_id and i.product_id = pr.barcode and  i.sales_id =  $last_insert_id ";
    $orderResult = $conn->query($sql);
    $orderData = $orderResult->fetch_array();
    $sales_id = $orderData[0];
    $product_id = $orderData[1];
    $price = $orderData[2];
    $qty = $orderData[3];
    $discount = $orderData[4];
    $total = $orderData[5];
    $date = $orderData[6];
    $grand_total = $orderData[7];
    $pay = $orderData[8];
    $balance = $orderData[9];
    $product_name = $orderData[10];
// create some HTML content
    $html = '<p align="center"><b style="font-size: 14px">Tutus Funny</b><br>
<i>Computer best lessons online</i>
</p>
                    <p align="left">
                    Order #  '.$last_insert_id.' </b>
                        <br>
                         Date # <b>'.$date.' </b>
                    </p>


                            <table class="table table-condensed">
                                <thead>
                                <tr>

                                    <td align="center"><strong>Pname</strong></td>
                                    <td align="center"><strong>Qty</strong></td>
                                    <td align="center"><strong>Price</strong></td>
                                    <td align="center"><strong>Total</strong></td>
                                </tr>
                                </thead>

 '.
                                $x = 1;
                                $last_insert_id = $_GET['last_id']; //
                                $orderResult = $conn->query($sql);
                                while($row = $orderResult->fetch_array()){
                                    ?>




                                    <tr>
                                     <td align="center">.$pname.</td>
                                     <td align="center">.$price.</td>
                                     <td align="center">.$qty.</td>
                                      <td align="center">.$total.</td>
                                    </tr>
        $x++;   } .'
                            </table>
<br>

                    <div  align="right">
                        Sub Total &nbsp;&nbsp;<b>'.$grand_total.'</b><br>
                          Pay  &nbsp;&nbsp; <b> '.$pay.'</b><br>
                           Due &nbsp;&nbsp;   <b>'.$balance.'</b>
                    </div>

                    <div align="center">
                        <i>60 b bank road badulla</i>
                    </div>
                </div>
           </div>


                ';

// output the HTML content
    $pdf->writeHTML($html, true, false, true, false, '');


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// reset pointer to the last page
    $pdf->lastPage();
    $pdf->Output();
}
?>

试试这个代码

  <?php
require_once('lib/master/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, [80, 230], true, 'UTF-8', false);

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetFont('dejavusans', '', 10);
$pdf->AddPage();
include("db.php");
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $last_insert_id = 51;
    $sql = "select i.sales_id,i.product_id,i.sell_price,i.qty,i.discount,i.total,s.date,s.grand_total,s.pay,s.balance,pr.p_name from sales_product i, sales s,product pr where s.id = i.sales_id and i.product_id = pr.barcode and  i.sales_id =  $last_insert_id ";
    $orderResult = $conn->query($sql);
    $orderData = $orderResult->fetch_array();
    $sales_id = $orderData[0];
    $product_id = $orderData[1];
    $price = $orderData[2];
    $qty = $orderData[3];
    $discount = $orderData[4];
    $total = $orderData[5];
    $date = $orderData[6];
    $grand_total = $orderData[7];
    $pay = $orderData[8];
    $balance = $orderData[9];
    $product_name = $orderData[10];
// create some HTML content
    $html = '<p align="center"><b style="font-size: 14px">Tutus Funny</b><br><i>Computer best lessons online</i></p><p align="left">Order #  '.$last_insert_id.' </b><br>Date # <b>'.$date.' </b>
         </p><table class="table table-condensed"><thead>
                                <tr><td align="center"><strong>Pname</strong></td>
                                    <td align="center"><strong>Qty</strong></td>
                                    <td align="center"><strong>Price</strong></td>
                                    <td align="center"><strong>Total</strong></td>
                                </tr>
                                </thead>';
                                $x = 1;
                                $last_insert_id = $_GET['last_id']; //
                                $orderResult = $conn->query($sql);
                                while($row = $orderResult->fetch_array())
                                {





                                    $html.='<tr>
                                     <td align="center">'.$pname.'</td>
                                     <td align="center">'.$price.'</td>
                                     <td align="center">'.$qty.'</td>
                                      <td align="center">'.$total.'</td>
                                    </tr>';
        $x++;   } 

                  $html.='</table>
<br>

                    <div  align="right">
                        Sub Total &nbsp;&nbsp;<b>'.$grand_total.'</b><br>
                          Pay  &nbsp;&nbsp; <b> '.$pay.'</b><br>
                           Due &nbsp;&nbsp;   <b>'.$balance.'</b>
                    </div>

                    <div align="center">
                        <i>60 b bank road badulla</i>
                    </div>
                </div>
           </div>';

// output the HTML content
    $pdf->writeHTML($html, true, false, true, false, '');


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// reset pointer to the last page
    $pdf->lastPage();
    $pdf->Output();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM