TCPDF如何在HTML里面写PHP代码
TCPDF how to write the PHP code inside the HTML
我正在使用 TCPDF 创建库存帐单打印件。我 运行 在将 while 循环放入 HTML 标记时出现问题,它出错了,我该如何正确编写它。我尝试了什么,所以我在下面写了。 date 和 lastinserted 以及 g运行dtotal pay balance 都显示得很好。只有我需要 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 <b>'.$grand_total.'</b><br>
Pay <b> '.$pay.'</b><br>
Due <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 <b>'.$grand_total.'</b><br>
Pay <b> '.$pay.'</b><br>
Due <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();
}
我正在使用 TCPDF 创建库存帐单打印件。我 运行 在将 while 循环放入 HTML 标记时出现问题,它出错了,我该如何正确编写它。我尝试了什么,所以我在下面写了。 date 和 lastinserted 以及 g运行dtotal pay balance 都显示得很好。只有我需要 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 <b>'.$grand_total.'</b><br>
Pay <b> '.$pay.'</b><br>
Due <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 <b>'.$grand_total.'</b><br>
Pay <b> '.$pay.'</b><br>
Due <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();
}