我正在尝试向以下代码添加if语句,只需要澄清一下它是否能做正确的工作。
Order #: <? echo $ORDERID?><br />
<br />
Pick-Up Date: <? echo $MYPICKUP?><br />
Comments: <? echo $COMMENTS?><br /><br />
<? echo $CART?><br />
Order total: $<? echo $GRANDTOTAL?><br />
Payment Method: <? echo $PAYMETHOD?></span><span class="TextB"><br />
尝试添加运费&amp;处理:在那里结果是:
<?php
$paypal = 'paypal';
$check = 'check';
if ($paymethod == $paypal)
{
echo "Shipping & Handling = $GRANDTOTAL * .045";
}
elseif ($paymethod == $check)
{
echo "Shipping & Handling = 0";
}
?>
但我的问题是,选择该选项后是否会显示运费和处理金额?
答案 0 :(得分:0)
是的,如果选择paymentmethod选项作为paypal,它将回显“Shipping&amp; Handling = $ GRANDTOTAL * .045”,如果检查,它将回显“Shipping&amp; Handling = 0”
答案 1 :(得分:0)
像这样:
<?php
$paypal = 'paypal';
$check = 'check';
if ($paymethod == $paypal)
echo "Shipping & Handling =". $GRANDTOTAL * .045;
elseif ($paymethod == $check)
echo "Shipping & Handling = 0";
else
echo "Invalid parameter.";
?>
如果您不想计算运费和;处理如上所述:
echo "Shipping & Handling = $GRANDTOTAL * .045";
答案 2 :(得分:0)
确保$paymethod
不是$PAYMETHOD
,它区分大小写。
并确保$paymethod
必须等于paypal
或check
,它也区分大小写。