php中嵌入的html条件if语句

php中嵌入的html条件if语句,php,html,if-statement,conditional,Php,Html,If Statement,Conditional,我觉得这应该很简单,但我没有得到我想要的结果。我有一个电子邮件注册表格,可以在我所有的网站上显示。如果他们碰巧以商店代码ama\br访问我的网站,电子邮件注册就会消失。这很好,而且有效。我的elseif语句与在所有门店视图中显示的表单不同,我希望此新表单仅在其门店代码ama_ca时显示。它对我不起作用,我看不出我的代码有任何问题。请帮忙。多谢各位 <?php if (Mage::app()->getStore()->getCode() != "ama_b

我觉得这应该很简单,但我没有得到我想要的结果。我有一个电子邮件注册表格,可以在我所有的网站上显示。如果他们碰巧以商店代码
ama\br
访问我的网站,电子邮件注册就会消失。这很好,而且有效。我的
elseif
语句与在所有门店视图中显示的表单不同,我希望此新表单仅在其门店代码
ama_ca
时显示。它对我不起作用,我看不出我的代码有任何问题。请帮忙。多谢各位

            <?php if (Mage::app()->getStore()->getCode() != "ama_br"):?>
                <ul>
                    <li><?php echo $this->__('Email Sign Up')?></li>
                    <li>
                        <form action="<?php echo $this->getUrl('email_preferences')?>" method="get" id="newsletter-validate-detail">
                            <input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address')?>" title="<?php echo $this->__('Enter Email address')?>' class="required-entry validate-email">
                            <button class="submit">+</button>
                            <input type="hidden" name="source" value="nt">
                        </form>
                    </li>
                    <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo')?></li>
                </ul>

            <?php elseif (Mage::app()->getStore()->getCode() == "ama_ca"):?>
                <ul>
                    <li><?php echo $this->__('Email Sign Up')?></li>
                    <li>
                <form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
                        <input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
                        <input type="hidden" name="CheckBox.Source.ca_footer" value="on">
                        <input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
                        <input type="hidden" id="submit" value="Sign Up">
                        </form>
                    </li>
                    <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo')?></li>
                </ul>
            <?php endif;?>


  • 说明 你做的每一件事都是对的,但你只是错过了一个诀窍仔细看看你的if语句逻辑,如果你的代码不等于ama_br,也就是说它可以等于ama_ca,因此它将在if语句中显示ama_ca的形式,以及ama_br中的任何其他字符串,因此您试图在代码上显示的表单等于ama_ca未显示。请尝试以下操作之一,它将解决您的查询

    代码

            <?php if (Mage::app()->getStore()->getCode() == "ama_ca"): ?>
              <ul>
                <li><?php echo $this->__('Email Sign Up') ?></li>
                <li>
                <form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
                <input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
                <input type="hidden" name="CheckBox.Source.ca_footer" value="on">
                <input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
                <input type="hidden" id="submit" value="Sign Up">
                </form>
                </li>
               <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
             </ul>
    
            <?php elseif (Mage::app()->getStore()->getCode() != "ama_br"): ?>
              <ul>
                <li><?php echo $this->__('Email Sign Up') ?></li>
                <li>
                  <form action="<?php echo $this->getUrl('email_preferences') ?>" method="get" id="newsletter-validate-detail">
                  <input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address') ?>" title="<?php echo $this->__('Enter Email address') ?>' class="required-entry validate-email">
                       <button class="submit">+</button>
                  <input type="hidden" name="source" value="nt">
                  </form>
                  </li>
                  <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
                 </ul>
            <?php endif; ?>
    
    
    

    • 逻辑。只执行
      if
      的一个块。因为你正在做一个
      =在第一个测试中测试,然后
      'ama_ca'!='ama\u br'
      为真,该块执行,完全跳过后面的
      =='ama\u ca'
      一个。首先检查
      ama\u ca
      。@此方法参考我的答案,它将解决您的查询anks@MarcB,我不知道该逻辑是如何工作的。多谢各位*谢谢你@Ahmer。我使用的第一个答案是基于逻辑的工作原理和更少的代码。
             <?php if (Mage::app()->getStore()->getCode() != "ama_br" && Mage::app()- >getStore()->getCode() != "ama_ca"): ?>
                <ul>
                 <li><?php echo $this->__('Email Sign Up') ?></li>
                  <li>
                  <form action="<?php echo $this->getUrl('email_preferences') ?>" method="get" id="newsletter-validate-detail">
                  <input name="email" type="text" id="newsletter" placeholder="<?php echo $this->__('Enter Email address') ?>" title="<?php echo $this->__('Enter Email address') ?>' class="required-entry validate-email">
                         <button class="submit">+</button>
                         <input type="hidden" name="source" value="nt">
                  </form>
             </li>
             <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo') ?></li>
            </ul>
      
            <?php elseif (Mage::app()->getStore()->getCode() == "ama_ca"): ?>
            <ul>
                <li><?php echo $this->__('Email Sign Up') ?></li>
            <li>
              <form method="post" action="http://enews.******.com/q/9MNK4U4iV9Mutb9YzTxF2zRWDIPgKoX0F0" accept-charset="UTF-8">
                  <input type="hidden" name="crvs" value="6hZNXcISD79ac2Empmsr2az_B3Qc5osTNmkOdNHleqhPIYmsxEOe6PbgaUo-3WBn_Vbgorrbk4qjekx7w4tljA">
                  <input type="hidden" name="CheckBox.Source.ca_footer" value="on">
                  <input name="email" type="text" id="newsletter" placeholder="Enter Email address" title="Enter Email address' class=" required-entry="">
                  <input type="hidden" id="submit" value="Sign Up">
              </form>
          </li>
             <li class="footer-promo"><?php echo $this->getChildHtml('footer_promo')  ?></li>
          </ul>
          <?php endif; ?>