[英]PHP: Only List Items With Quantity Value Greater Than 0 In If Statement
'Ello 埃洛
I'm trying to get the items from a client populated "order form" to ONLY list the items that the client has designated a quantity value of 1 or more to be sent as a Purchase Order receipt that is generated and sent via email once they hit Submit. 我正在尝试从客户端填充的“订单表单”中获取项目,以仅列出该客户指定数量值等于或大于1的项目,这些项目将作为采购订单收据发送,并在生成后通过电子邮件发送点击提交。
Here's what I have so far on that part: 到目前为止,这是我在那部分内容:
$i = 1;
$imax = 4;
echo "Products<br />";
echo "-------------------------------------------------------------<br />";
while ($i <= $imax) {
$itemqty = ${'qty'.$i};
$itempn = ${'pn'.$i};
$itemdesc = ${'desc'.$i};
$itemprice = ${'value'.$i};
$itemtotalprice = ${'elinetotal'.$i};
if ($itemqty !== 0) {
echo $itemqty . " x " . $itemdesc . " (" . $itempn . ") @ $" . $itemprice . " ea. = $" . $itemtotalprice . "<br />";
}
$i++;
}
It lists everything correctly, except it doesn't disregard the items with a value of 0. It'll list them like this: 它会正确列出所有内容,只是不会忽略值为0的项目。它将这样列出它们:
Products
-------------------------------------------------------------
0 x Item #1 Description (HOSE-12) @ $155.00 ea. = $0.00
5 x Item #2 Description (GAUGE-2) @ $51.00 ea. = $255.00
0 x Item #3 Description (PTC) @ $0.70 ea. = $0.00
10 x Item #4 Description (PT-234R) @ $15.94 ea. = $159.40
It may be the easiest fix, but can anyone shed some light on this? 这可能是最简单的解决方法,但是任何人都可以对此有所了解吗? I'd greatly appreciate it!
我将不胜感激!
My initial guess is $itemqty
is the string '0'
. 我最初的猜测是
$itemqty
是字符串'0'
。 Try using the not equal operator, eg 尝试使用不等于运算符,例如
if ($itemqty != 0)
instead of the not identical operator, ie !==
而不是不相同的运算符,即
!==
Otherwise, you could try casting the $itemqty
assignment as an integer, eg 否则,您可以尝试将
$itemqty
分配转换为整数,例如
$itemqty = (int) ${'qty'.$i};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.