gpt4 book ai didi

php - 在连接 MySQL 和 PHP 时将 HTML 代码存储在变量中

转载 作者:行者123 更新时间:2023-11-29 06:04:03 25 4
gpt4 key购买 nike

我有一段代码要存储在一个变量中,这样我就可以使用 dompdf 将其转换为 PDF

$html = '<div class="receiptContainer">
<center>
<img src="Images/logo.png" width="175px">
<h4>GOKUJOU JAPANESE RESTAURANT</h4>
<p>Total Gas Station, Hibbard Ave., Looc,<br>Dumaguete City, 6200 Negros Oriental, Philippines <br>
09985555175 | 422-1435 <br>
<?php echo date("Y-m-d h:i:sA"); ?>
</p>

<table width="90%" style="text-align: center;">
<tr>
<th>DESCRIPTION</th>
<th>QTY</th>
<th>PRICE</th>
<th>TOTAL</th>
</tr>
<tr>
<td></td>
</tr>
<?php
$query = mysqli_query($con, "SELECT * FROM orders WHERE customerID = '".$_SESSION['customer']."' AND status = '"Checked Out"'");
while($row = mysqli_fetch_row($query)){
?>
<tr>
<td><?php echo $row[3]; ?></td>
<td><?php echo $row[5]; ?></td>
<td><?php echo $row[4]; ?></td>
<td><?php echo $row[6]; ?></td>
</tr>
<?php
}
$total = mysqli_query($con, "SELECT SUM(total) AS grandTotal FROM orders WHERE customerID = '".$_SESSION['customer']."' AND status = '"Checked Out"' GROUP BY customerID");
$row = mysqli_fetch_row($total);
$sum = $row[0];
?>
<tr>
<!-- break space -->
<tr></tr><tr></tr><tr></tr><tr></tr>
<tr></tr><tr></tr><tr></tr><tr></tr>
<tr></tr><tr></tr><tr></tr><tr></tr>

<td colspan="1" style="text-align: left">GRAND TOTAL: <?php echo $sum; ?></td>
<td colspan="3"></td>
</tr>
<tr style="text-align: left">
<td colspan="1">CASH: <?php echo $_SESSION['"cash"']; ?></td>
<td colspan="3"></td>
</tr>
<tr style="text-align: left">
<td colspan="1">CHANGE: <?php echo $_SESSION['"cash"'] - $sum; ?></td>
<td colspan="3"></td>
</tr>
</table>
</center>
</div>';
//start PDF generation
$dompdf = new Dompdf();
$dompdf->loadHTML($html);
$dompdf->setPaper(array(0, 0, 1080, 500), 'landscape');
$dompdf->render();
$dompdf->stream("samplepdf");
?>

这是我构建代码的方式,它返回一个错误:

Parse error: syntax error, unexpected '"' in C:\xampp\htdocs\Gokujou\checkout.php on line 107

这是第 107 行:

$query = mysqli_query($con, "SELECT * FROM orders WHERE customerID = '".$_SESSION['customer']."' AND status = '"Checked Out"'");

如何正确连接此 MySQL 语句?

最佳答案

如果你使用 ",你不需要在 php 中使用连接运算符,只有在使用 ' 时才需要。然后你可以像这样转换你的赋值:

$query = mysqli_query($con, "SELECT * FROM orders WHERE customerID = '$_SESSION['customer']' AND status = 'Checked Out'");

但我们可以将你所做的转化为这个(与运营商一起修复)

$query = mysqli_query($con, "SELECT * FROM orders WHERE customerID = '".$_SESSION['customer']."' AND status = 'Checked Out'");

关于php - 在连接 MySQL 和 PHP 时将 HTML 代码存储在变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42929809/

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