douwei8295
2017-04-14 22:14
浏览 1.2k
已采纳

将PHP if语句嵌入到HTML中

feel like i have tried every possible way..right now it is just skipping over the if statement and posting out the html.

<? if ($departmentID == 1 :  ?>
    <h4>Outreach Questions <?= $departmentID ?><h4>
    <h4>Why Interested</h4>
    <ul>
        <strong>Why are you interested in volunteering as an outreach docent? </strong> <?php echo $whyInterested ?>
    </ul>

    <h4>Wildlife Issues</h4>
    <ul>
        <strong>What’s an environmental or wildlife issue you feel passionately about, and why? </strong> <?php echo $wildlifeIssue ?>
    </ul>
    <h4>Public Speaking</h4>
    <ul>
        <strong>Do you have prior experience speaking to the public? Please describe. </strong> <?php echo $publicSpeaking ?>
    </ul>
    <h4>Wildlife Groups</h4>
    <ul>
        <strong>Do you belong to any animal rights groups (PETA, The Humane Society, etc.)? If so, which ones? </strong> <?php echo $wildlifeGroup ?>
    </ul>
    <h4>Contributions</h4>
    <ul>
        <strong>What do you think you’d bring to the outreach volunteer team?</strong> <?php echo $bringToTeam ?>
    </ul>
<? endif; ?>
</div>

the idea is to do an else if with id ==2 and so on..but it is pushing out all the HTML regardless of the departmentID.

thanks in advance.

图片转代码服务由CSDN问答提供 功能建议

感觉我已经尝试了所有可能的方式......现在它只是跳过if语句并发布了 HTML

 <代码>&LT ;?  if($ departmentID == 1:?&gt; 
&lt; h4&gt; Outreach Questions&lt;?= $ departmentID?&gt;&lt; h4&gt; 
&lt; h4&gt;为什么感兴趣&lt; / h4&gt; 
&lt; ul&gt;  
&lt; strong&gt;为什么您对志愿服务作为外展讲师感兴趣?&lt; / strong&gt;&lt;?php echo $ whyInterested?&gt; 
&lt; / ul&gt; 
 
&lt; h4&gt;野生动物问题&lt;  / h4&gt; 
&lt; ul&gt; 
&lt; strong&gt;您对此充满热情的环境或野生动物问题是什么?为什么?&lt; / strong&gt;&lt;?php echo $ wildlifeIssue?&gt; 
&lt; / ul&gt;  ; 
&lt; h4&gt;公开演讲&lt; / h4&gt; 
&lt; ul&gt; 
&lt; strong&gt;您之前有过与公众交流的经历吗?请描述一下。&lt; / strong&gt;&lt;?php echo $ publicSpeaking  ?&gt; 
&lt; / ul&gt; 
&lt; h4&gt;野生动物群组&lt; / h4&gt; 
&lt; ul&gt; 
&lt; strong&gt;您是否属于任何动物权利组织(PETA,人道社会等)  。)?如果是,哪些?&lt; / strong&gt;&lt;?php echo $ wildlifeGroup?&gt; 
&l  t; / ul&gt; 
&lt; h4&gt;捐款&lt; / h4&gt; 
&lt; ul&gt; 
&lt; strong&gt;您认为您将如何为外展志愿者团队带来什么?&lt; / strong&gt;  &lt;?php echo $ bringToTeam?&gt; 
&lt; / ul&gt; 
&lt;? 万一;  ?&gt; 
&lt; / div&gt; 
   
 
 

如果id == 2等等,我们的想法就是做其他事情。但是它推出了所有 HTML,无论departmentID是什么。

提前感谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题