Php FPDF&;While循环
我目前正在编写一个发票脚本,该脚本当前从MySql中提取信息,然后将该信息转换为PDF格式,并使用PHPmailer发送电子邮件 我坚持的部分是如何将其转换为PDF格式。我想能够发布orderid到下一页,然后再转换成PDF 我在下面附上了我的脚本以寻求帮助Php FPDF&;While循环,php,mysql,pdf,while-loop,fpdf,Php,Mysql,Pdf,While Loop,Fpdf,我目前正在编写一个发票脚本,该脚本当前从MySql中提取信息,然后将该信息转换为PDF格式,并使用PHPmailer发送电子邮件 我坚持的部分是如何将其转换为PDF格式。我想能够发布orderid到下一页,然后再转换成PDF 我在下面附上了我的脚本以寻求帮助 <?php session_start(); $username = $_SESSION['username']; $con = mysqli_connect('***', '***', '***', '
<?php
session_start();
$username = $_SESSION['username'];
$con = mysqli_connect('***', '***', '***', '***');
if (!isset($con)) {
die("Connection to Aurora System failed.");
}
$orderid = $_POST['order_id'];
?>
<!doctype html>
<html>
<body class="body page-orderview clearfix">
<div class="element"></div>
<p class="text text-1">SMKD Field Force</p>
<a href="front.php"><img class="image" src="images/smkd_logo.png"></a>
<p class="text text-2">Welcome</p>
<p class="text text-3">Order <?php echo "$orderid"; ?>
<table>
<tr>
<th>Product Title</th>
<th>Nicotine Strength</th>
<th>Quantity</th>
<th>Price (inc. VAT)</th>
</tr>
<?php
$query = "SELECT `product`, `variant`, `quantity` FROM orders_detail WHERE order_id = '$orderid'";
$result = mysqli_query($con, $query);
$quantitytotal = 0;
$quantityline = - 0;
while ($row = mysqli_fetch_assoc($result)) {
$product = $row['product'];
$stuff = $row['quantity'];
$variant = $row['variant'];
$linequantity = $stuff;
$quantitytotal += $stuff;
$pricequery = "SELECT product_price FROM products WHERE product_name = '$product'";
$priceresult = mysqli_query($con, $pricequery);
$pricetag = 0;
$priceline = 0;
while ($rowprice = mysqli_fetch_assoc($priceresult)) {
$price = $rowprice['product_price'];
$pricetag += $price;
$priceline = $price;
}
$linetotal = $priceline * $linequantity;
echo '<tr><td>' . $product .' </td> ' . '<td>' . $variant . '</td>' . ' <td> ' . $linequantity . '</td>' . '<td> £' . $linetotal . '</td> </tr>';
}
$total = $pricetag * $quantitytotal;
?>
<tr><td>Total Ex Vat:</td><td> Total Inc Vat:</td></tr>
<tr><td><?php echo "£" . ($total / 1.2);?></td>
<td><?php echo "£" . $total; ?></td></tr>
</table>
</p><br>
<form method="post" action"pdfinvoice.php">
<input type="hidden" value="<?php echo $orderid; ?>" name="orderid">
</form>
Submit button goes here
</body>
</html>
SMKD野战部队
欢迎光临
订单
产品名称
尼古丁浓度
量
价格(含增值税)
除增值税总额:含增值税总额:
只要在样式和html元素方面不要太复杂,我建议您看看,它是一个功能强大的html到PDF转换库,支持很多html
只是表单之类的东西在pdf中不起作用,所以不要包含它们(它们可能会被呈现,也可能不会被呈现,取决于确切的html标记)。事实上,我几周前刚刚完成了同样的任务。但是,我的页面不显示pdf。签出完成后,页面将显示一条成功消息,并通过电子邮件将pdf发送给用户
下载并将FPDF库包含在php文件中后。这只是创建FPDF对象、添加到它并输出它的问题
require "Resources/PDF/fpdf.php";
$pdf = new FPDF();
$pdf->SetAutoPageBreak(true, 0);
$pdf->SetLeftMargin(8);
$pdf->AddPage();
$pdf->SetFont('Arial','B',20);
$pdf->SetTextColor(255);
$pdf->SetFillColor(0,153,204);
$pdf->Cell(194,10,'MyCompany Inc.','LRT',0,'L', true);
$pdf->Ln();
$pdf->SetFont('Arial','I',12);
$pdf->Cell(97,10,'Invoice #: '.$id.''.$cnt.'','LB',0,'L', true);
$pdf->Cell(97,10, "Date: ".date("d-m-Y")." ",'RB',0,'R', true);
$pdf->Ln();
$pdf->SetTextColor(0,153,204);
$pdf->SetFont('Arial','B',14);
$pdf->Cell(40,10,'Ship to:',0,4);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','I',12);
$pdf->Cell(40,5, $_POST['shippingName'],0,5);
$pdf->Cell(40,5, $COMP,0,6);
$pdf->Cell(40,5, $EMAIL,0,6);
$pdf->Cell(40,5, $_POST['shippingPhoneNumber'],0,7);
$pdf->Cell(40,5, $_POST['shippingAddress'],0,8);
$pdf->Cell(40,5, $_POST['shippingPostalCode'],0,9);
$pdf->Cell(40,5, $_POST['shippingCity'],0,10);
$pdf->Cell(40,5, $_POST['shippingProvince'],0,11);
$pdf->Cell(40,5, $_POST['shippingCountry'],0,12);
$pdf->Output(); //should display the pdf to the page
输出(“文件路径”);可以将pdf保存到目录中,然后通过电子邮件发送文件。
上面将创建一个标题并列出通过$\u POST变量传入的用户信息
FPDF文档有时会有所帮助