我是PHP的初学者,所以请耐心等待我。
我目前的情况是我遇到问题,打印订单会为我们的餐厅带来大量纸张。
Print out看起来像这样:
Receipt #: 0000
Cashier: Name here
Table #: table name
Client #: ID here
Date: 2017-03-11 8:26 PM
QTY: 4
Order:
Item 1
----------------------------------
Receipt #: 0000
Cashier: Name here
Table #: table name
Client #: ID here
Date: 2017-03-11 8:26 PM
QTY: 1
Order:
Item 2
我一般都想以这种方式打印以节省纸张
Receipt #: 0000
Table #: table name
Client #: ID here
Date: 2017-03-11 8:26 PM
Cashier: Name here
QTY: 4
Order:
Item 1
Notes:
Cashier: Name here
QTY: 1
Order:
Item 2
Notes:
我目前的查询和回声是这样的:
$sql = "SELECT * FROM orders WHERE catid = 'Drinks' and printed = 'ticket' and status = 'active' and groupid = '".$_GET['groupid']."' and tid NOT LIKE 'Upstairs%' Order By oid asc ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$oid = $row{'oid'};
$product = $row['pname'];
$groupidx = $row['groupid'];
$printreceipt = $row['printreceipt'];
?>
<h4 class="printableArea" style="line-height:20px;font-size:15px; margin:0px 0px 0px 5px; color: <?php echo $color;?>; font-family: Courier New "><hr style="margin:0px;"/><span style="font-weight:900;"> Receipt #: <?php $newinfo = $row{'info'}; echo $row{'info'}; ?> <br> Cashier: <?php echo $row['user'];?><br> Table #:
<?php echo $row['tid']; ?> <br> Client #: <?php echo $row['cid']; ?> <br> Date: <?php echo date('Y-m-d h:i A', strtotime($row['date']))?><br> QTY: <?php echo $row['qty']; ?> <br>Order:<br> <?php if($row['viet']==""){ echo $product;}else{ echo $row['viet']; } ? > <br> <?php echo $row['attr']; ?> <br> Notes: <br> <?php echo $row['extraoptions']; ?></span></h4>
<?php
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql2 = "UPDATE orders SET printed='Yes' WHERE catid = 'Drinks' and oid = '$oid' and (status <> 'waiting' and status <> 'deleted')";
if ($conn->query($sql2) === TRUE) {
// echo "Record updated successfully";
?>
<script>
<?php
if(!empty($printreceipt)){
$printreceipt = $printreceipt;
}else {$printreceipt='Bar';}
?>
答案 0 :(得分:0)
您需要拆分范围的输出,以便只打印一次“标题”。这是完成任务的一种方法:
我不知道如何处理这个部分,所以我把它从我的例子中删除了。此外,还不清楚“物品”是如何使用的?代码中没有匹配的标签。
<?php echo $row['attr']; ?> <br>
您可能需要根据自己的喜好“调整”所需的输出,因为我只是在下面的示例中重复使用您的信息。
首先,在while循环之前,添加此变量:
$showHeader = true;
while(($row = $result->fetch_assoc()) {
然后我拆分跨度文本以使用应该显示一次标题的变量(到目前为止的收据),然后所有其他数据(收银员到笔记 - 除了Item,我上面提到的)应该显示为尾随行在标题下面。
<h4 class="printableArea" style="line-height:20px;font-size:15px; margin:0px 0px 0px 5px; color: <?php echo $color;?>; font-family: Courier New "><hr style="margin:0px;"/>
<span style="font-weight:900;">
<?php
if ( true === $showHeader ) { // to achieve a 'single header'
$showHeader = false; // avoid other headers
echo 'Receipt #: ' . $row['info'] . '<br><br>';
echo 'Table #: ' . $row['tid'] . '<br>';
echo 'Client #: ' . $row['cid'] . '<br>';
echo 'Date: ' . date('Y-m-d h:i A', strtotime($row['date'])) . '<br>';
}
echo 'Cashier: ' . $row['user'] . '<br>';
echo 'QTY: ' . $row['qty'] . '<br>';
echo 'Order: ' . '<br>';
if ( $row['viet']=="") {
echo $product;
}
else {
echo $row['viet'];
}
echo '<br>' . 'Notes:' . '<br>' . $row['extraoptions'];
?>
</span></h4>
这是一般的想法。如果可能需要澄清,请添加评论。