gpt4 book ai didi

php - FPDF 和 While 循环

转载 作者:行者123 更新时间:2023-11-29 19:21:49 25 4
gpt4 key购买 nike

我目前正在开发一个发票脚本,该脚本当前从 MySql 中提取信息,然后将该信息转换为 PDF 并使用 PHPmailer 通过电子邮件发送。

我所困惑的部分是如何将其转换为 PDF。我希望能够将 orderid 发布到后续页面,然后将其转换为 PDF。

我在下面附上了我的脚本以获取一些帮助。

  <?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>

我不会反对将整个页面转换为 PDF,但据我了解,FPDF 不可能实现这一点。

问候并非常感谢!

最佳答案

只要您在样式和 html 元素方面不要使其过于复杂,我建议您查看 https://github.com/dompdf/dompdf ,它是一个非常强大的 HTML 到 PDF 转换器库,并且支持相当多的 HTML。

仅表单之类的内容无法在 pdf 中使用,因此不要包含这些内容(它们可能会或可能不会呈现,具体取决于确切的 html 标签。)

关于php - FPDF 和 While 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42394138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com