简体   繁体   English

多个促销代码

[英]Multiple Promo Codes

Complete n00b here so please be forgiving. 在此处完成n00b,请原谅。 I inherited a website and it has code in it to reduce the price of a one year membership by $10. 我继承了一个网站,该网站中包含代码,可将一年会员的价格降低10美元。 I need to add another discount, "LEO" that would reduce the price by $15. 我需要添加另一个折扣“ LEO”,以将价格降低15美元。 I thought I could mimic the original code and everything would be OK but when I try it, it does not work properly. 我以为我可以模仿原始代码,一切都会好起来的,但是当我尝试时,它无法正常工作。 I'm hoping it is just a syntax thing? 我希望这只是语法问题?

Here is the original code: 这是原始代码:

  <tr>
    <td class='bottomborder'><div align='center'>
    <span id='bobcontent1-title'><input type='radio' name='MembershipTerm' class='join_form_bullet' value='";
      if($promocode == 'CIG9237'){echo("CigarFest Individual 1 Year");}
      else {echo("Individual 1 Year");}
      print"' checked='checked'></span>
    </div></td>
    <td class='bottomborder'>&nbsp;1 Year</td>
    <td class='bottomborder'>";
      if($promocode == 'CIG9237'){echo("$25");}
        else {echo("$35");}                                     
    print"</td>
    <td class='bottomborder'><span class='text_red'>";
    if($promocode == 'CIG9237'){echo("$10.00!");}
      else {echo(" ");}
    print"</span></td>
    <td class='bottomborder'>One Time Charge</td>
  </tr>

And here is what I tried without luck 这是我没有运气的尝试

  <tr>
    <td class='bottomborder'><div align='center'>
    <span id='bobcontent1-title'><input type='radio' name='MembershipTerm' class='join_form_bullet' value='";
      if($promocode == 'CIG9237'){echo("CigarFest Individual 1 Year");}
      if($promocode == 'LEO'){echo("Law Enforcement 1 Year");}
      else {echo("Individual 1 Year");}
      print"' checked='checked'></span>
    </div></td>
    <td class='bottomborder'>&nbsp;1 Year</td>
    <td class='bottomborder'>";
      if($promocode == 'CIG9237'){echo("$25");}
      if($promocode == 'LEO'){echo("$20");}
        else {echo("$35");}                                     
    print"</td>
    <td class='bottomborder'><span class='text_red'>";
    if($promocode == 'CIG9237'){echo("$10.00!");}
    if($promocode == 'LEO'){echo("$15.00!");}
      else {echo(" ");}
    print"</span></td>
    <td class='bottomborder'>One Time Charge</td>
  </tr>

When I add the LEO line then the pricing displays $25$35 for the original promo code of CIG9237 but seems to look correct for the LEO code. 当我添加LEO行时, CIG9237的原始促销代码的价格显示$25$35 ,但对于LEO代码似乎看起来正确。

Change all the if($promocode == 'LEO') lines that you added to elseif($promocode == 'LEO') . 更改添加到elseif($promocode == 'LEO')所有if($promocode == 'LEO')行。

What's happening is that the else clause after it is being run whenever the promo code is not LEO , instead of when neither of the promo codes matches. 发生的情况是,只要促销代码不是LEO ,就会运行该语句之后的else子句,而不是两个促销代码都不匹配时。

The second if statement will get executed even if the first condition is successful, in which case the condition of the second if statement echos the value in the else block. 即使第一个条件成功,第二条if语句也将被执行,在这种情况下,第二条if语句的条件将回显else块中的值。 To avoid this, use an elseif statement instead. 为避免这种情况,请改用elseif语句。 When an elseif is used, it will only be evaluated if the original condition in the first if statement is false. 使用elseif时,只有在第一个if语句中的原始条件为false时,才会对其进行评估。

Your first set of if statements isn't executing as you expect. 您的第一组if语句未按预期执行。 The else condition is matching to the second if statement so if $promocode is 'CIG9237' then the first if statement executes and the else statement will execute too since $promocode is not equal to 'LEO' . else条件与第二个if语句匹配,因此,如果$promocode'CIG9237'则第一个if语句执行,并且$promocode不等于'LEO'else语句也将执行。

Basically, where you have this: 基本上,您在这里:

if($promocode == 'CIG9237'){echo("$25");}
if($promocode == 'LEO'){echo("$20");}
else {echo("$35");}

You should have this: 你应该有这个:

if($promocode == 'CIG9237'){echo("$25");}
elseif($promocode == 'LEO'){echo("$20");}
else {echo("$35");}

To link all the statements together (now only one of the statements will be executed). 将所有语句链接在一起(现在仅执行其中一条语句)。

And the same goes for further down, it should be this: 同样,进一步的下降应该是这样的:

if($promocode == 'CIG9237'){echo("$10.00!");}
elseif($promocode == 'LEO'){echo("$15.00!");}
else {echo(" ");}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM