Php 基于变量值隐藏表的特定行
我正在用php处理发票。我只想在发票上有到期部分时才显示到期部分,否则它应该保持隐藏状态。在my printOrder.php中,代码如下所示: 以下是printOrder.php文件的总代码:Php 基于变量值隐藏表的特定行,php,Php,我正在用php处理发票。我只想在发票上有到期部分时才显示到期部分,否则它应该保持隐藏状态。在my printOrder.php中,代码如下所示: 以下是printOrder.php文件的总代码: <?php require_once 'core.php'; $orderId = $_POST['orderId']; $sql = "SELECT order_date, client_name, client_address, client_contact, sub_to
<?php
require_once 'core.php';
$orderId = $_POST['orderId'];
$sql = "SELECT order_date, client_name, client_address, client_contact, sub_total, vat, total_amount, discount, grand_total, paid, due, invoice_no FROM orders WHERE order_id = $orderId";
$orderResult = $connect->query($sql);
$orderData = $orderResult->fetch_array();
$orderDate = $orderData[0];
$clientName = $orderData[1];
$clientAddress = $orderData[2];
$clientContact = $orderData[3];
$subTotal = $orderData[4];
$vat = $orderData[5];
$totalAmount = $orderData[6];
$discount = $orderData[7];
$grandTotal = $orderData[8];
$paid = $orderData[9];
$due = $orderData[10];
$invoiceNo = $orderData[11];
$orderItemSql = "SELECT order_item.product_id, order_item.rate, order_item.quantity, order_item.total,
product.product_name, order_item.categories_name, order_item.subcategory_name, order_item.brand_name FROM order_item
INNER JOIN product ON order_item.product_id = product.product_id
WHERE order_item.order_id = $orderId";
$orderItemResult = $connect->query($orderItemSql);
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
?>
<table border="0" cellpadding="5" style="width:100%;font-size:10px;border:0px solid black;text-align:center;margin-bottom:15px;">
<thead>
<tr>
<th colspan="2">
<img style="float:left" src="assests/images/logo.jpg" width="80"/>
</th>
<th></th>
<th colspan="5">
<div>
<div style="font-size:14px; text-align:right; font-weight:bold">Sylhet Gym Supplements & Online Store</div>
<div style="font-size:8px; text-align:right; font-weight:normal; line-height:10px; padding:4px 0 4px 30px">One of the best UK and USA suppliers in Gym Food Supplements to support A healthy lifestyle. We supply To retailer Bodybuilding.com supplement Online Market, Sylhet, Bangladesh</div>
<div style="font-size:9px; text-align:right; font-weight:normal">R.B Complex (Level-4), East Zindabazar, Sylhet</div>
<div style="font-size:9px; text-align:right; font-weight:normal; line-height:18px">Cell: 01725-275252</div>
</div>
</th>
</tr>
<tr>
<th colspan="8" style="text-align:left;margin-left:0;padding-left:0"><span style="font-size:10px;background-color:#000;color:#fff;padding:2px 15px 4px">Invoice Details</span></th>
</tr>
<tr>
<th colspan="4" bgcolor="#f4f4f4" style="padding:5px 15px; text-align:left"><b>Mr. <?php echo $clientName; ?><b><br><p style="font-weight:normal;line-height:14px;"><?php echo $clientAddress; ?><br><?php echo $clientContact; ?></p></th>
<th colspan="4" bgcolor="#f4f4f4" style="line-height:14px;padding:5px 15px; font-weight:normal;text-align:right">Invoice No : <b><?php echo $invoiceNo; ?></b><br>Invoice Date : <b><?php echo $orderDate; ?></b><br><br>Paid Amount : Tk <span style="font-size:12px;font-weight:bold"><?php echo $paid; ?></span> Only</th>
</tr>
<tr>
<th colspan="8"></th>
</tr>
</thead>
<tbody>
<tr>
<th bgcolor="#f4f4f4">Sl.</th>
<th bgcolor="#f4f4f4" colspan="4" style="text-align:center">Product Description</th>
<th bgcolor="#f4f4f4" style="width:80px">Rate</th>
<th bgcolor="#f4f4f4" style="width:80px">Qty</th>
<th bgcolor="#f4f4f4" style="text-align:right;width:80px">Total</th>
</tr>
<?php
$x = 1;
while($row = $orderItemResult->fetch_array()) {
?>
<tr>
<th style="font-size:9px; font-weight:normal;"><?php echo $x; ?></th>
<th colspan="2" style="font-size:10px; font-weight:bold; text-transform:uppercase; text-align:left"><?php echo $row[4]; ?></th>
<th colspan="2" style="font-size:9px; font-weight:normal; text-align:left">A Product of <b><?php echo $row[7]; ?></b><br>It\'s Flavor is <b><?php echo $row[5]; ?></b> (<?php echo $row[6]; ?>)</th>
<th style="font-size:9px; font-weight:normal;"><?php echo $row[1]; ?></th>
<th style="font-size:9px; font-weight:normal;"><?php echo $row[2]; ?></th>
<th style="font-size:9px; font-weight:normal;text-align:right"><?php echo $row[3]; ?></th>
</tr>
<?php
$x++;
} // /while
?>
<tr>
<th></th>
</tr>
<tr>
<th colspan="8" style="border-top:1px solid #eee"></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th colspan="3" style="font-size:9px; font-weight:bold; line-height:8px; text-align:right">Total Amount</th>
<th style="font-size:9px; font-weight:normal; line-height:8px; text-align:right"><?php echo $totalAmount; ?></th>
</tr>
<tr>
<?php
if ($due > 0) {
echo '<th colspan="3" style="border:1px solid #ccc">Condition : '.$due.' Tk will be T.T</th>';
} else {
echo '<th colspan="3"></th>';
}
?>
<th></th>
<th colspan="3" style="font-size:9px; font-weight:bold; line-height:8px; text-align:right">Discount</th>
<th style="font-size:9px; font-weight:normal; line-height:8px; text-align:right"><?php echo $discount; ?></th>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th colspan="3" style="font-size:9px; font-weight:bold; line-height:8px; text-align:right">Grand Total</th>
<th style="font-size:9px; font-weight:normal; line-height:8px; text-align:right"><?php echo $grandTotal; ?></th>
</tr>
<tr>
<th colspan="8" bgcolor="#f4f4f4" style="text-align:right;text-transform:capitalize">Amount (In Words) : <?php echo $f->format($grandTotal); ?> Taka Only.</th>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="8" style="position:absolute; width:100%; bottom:50px;"><span style="float:left;border-top:1px solid #ccc"> Customer Signature </span><span style="float:right;border-top:1px solid #ccc;margin-right:20px"> For Sylhet Gym Supplements </span></th>
</tr>
<tr>
<th colspan="8" style="background-color: #eee; color: #555; position:absolute; width:100%; height:9px; line-height:9px; bottom:0; font-size: 7px">Powered By 7CoderIT. For assistance call on 01744-123456</th>
</tr>
</tfoot>
</table>
<?php
$connect->close();
?>
Sylhet健身房补充品和在线商店
英国和美国最好的健身房食品补充剂供应商之一,支持健康的生活方式。我们向零售商Bodybuilding.com supplement Online Market(孟加拉国Sylhet)供货
Sylhet Zindabazar东部R.B综合体(4级)
电话:01725-275252
发票明细
Mr.
发票编号:
发票日期:
支付金额:仅Tk
Sl。
产品说明
比率
数量
全部的
产品的味道是()
总金额
优惠
总计
金额(大写):仅塔卡。
Sylhet健身房补充剂的客户签名
由7CoderIT提供动力。如需帮助,请致电01744-123456
为了实现我的愿望,我几乎没做什么改变。之后,代码如上图所示。只需正确检查到期金额,我假设您得到到期金额0或null或某个值
<?php
if($due>0&&$due!=""){
?>
<tr>
<th colspan="2"><?php echo $due; ?></th>
</tr>
<?php
}
?>
如果$due变量不能帮助您做出决定,那么请检查决定该到期部分的变量,将到期部分包含在If条件中,如下所示(通用PHP)
if(condition){//仅当您的条件为真时,才会打印此tr。
回音“…”;
}
更新:在表中显示条件行的示例
单个PHP文件
<?php
$total_amount = 100;
$due = 20;
$data = array();
?>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach($data as $d){
?>
<tr>
<td></td>
<td></td>
</tr>
<?php
}
?>
<tr>
<th colspan="2"><?php echo $total_amount ?></th>
</tr>
<?php
if($due>0&&$due!=""){
?>
<tr>
<th colspan="2"><?php echo $due; ?></th>
</tr>
<?php
}
?>
</tbody>
</table>
使用td和th的colspan属性与表中的列数匹配。什么是付费的?根据定义,可能使用
CASE
或coalesce
。问题已经存在。如果金额为零,我无法隐藏到期价值行。实际上我把html和php搞混了。然后将php和html的标记分开。这是最后一种方法:现在它工作得很好。是的,@webDev,请删掉你答案中的所有其他片段,只为条件句提供指导。那么你就不会给出任何关于其他坏表结构的误导性信息了。当我第一次来到StackOverflow时,我的第一篇文章肯定不是“获奖的”。有一个学习曲线。可能是重复的,我无法在html中运行该条件。它在第105行的C:\xampp\htdocs\demo\printOrder.php中显示了解析错误:语法错误,意外的“if”(T_if),将所有php代码包含在标记中。如果使用php字符串打印表,请先断开字符串,然后使用条件。这个错误只是因为你把html和php代码弄乱了。请看一下如何在php中包含html代码,以及如何在html中同时包含php代码。我刚刚发布了如何做到这一点的想法,或者发布了您的完整代码,说明您是如何以php字符串的形式编写php代码的$表='…';echo$表;我是php的新手。这是我的错,我不能得到它。只要分解它,编写php标记并编写html表。在php字符串中使用所有html代码是错误的做法。难以调试且令人恼火。请看我的更新,并根据该结构创建一个页面,仔细查看我在哪里打开了php标记,在哪里关闭了php标记。很遗憾,我没有提出一个明显的问题。对此我很抱歉。我急切地等待着那封信。迫不及待地想学习新方法。短暂性脑缺血发作
<?php
$total_amount = 100;
$due = 20;
$data = array();
?>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach($data as $d){
?>
<tr>
<td></td>
<td></td>
</tr>
<?php
}
?>
<tr>
<th colspan="2"><?php echo $total_amount ?></th>
</tr>
<?php
if($due>0&&$due!=""){
?>
<tr>
<th colspan="2"><?php echo $due; ?></th>
</tr>
<?php
}
?>
</tbody>
</table>