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

将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.

  • 写回答

2条回答 默认 最新

  • douchun1859 2017-04-15 01:43
    关注

    <?php if ($departmentID == 1) {

    echo " <h4>Outreach Questions = '$departmentID' </h4> #all html below

    </ul>";} # ends block and closes echo
    ?> </div>

    Try this it uses php to echo out all of the html if the case is true otherwise no html gets echoed

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?