【发布时间】:2017-08-13 06:40:34
【问题描述】:
我有一段代码要存储在一个变量中,这样我就可以使用 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");
?>
这就是我构建代码的方式,它返回一个错误:
解析错误:语法错误,意外的 '"' in C:\xampp\htdocs\Gokujou\checkout.php 在第 107 行
这是第 107 行:
$query = mysqli_query($con, "SELECT * FROM orders WHERE customerID = '".$_SESSION['customer']."' AND status = '"Checked Out"'");
如何正确连接这个 MySQL 语句?
【问题讨论】:
-
我可以建议你使用一些 IDE 吗?因为在断言数据时代码中存在错误
标签: php mysql concatenation