如何在if语句中回显PHP和HTML [英] How to echo PHP and HTML in if statement

查看:157
本文介绍了如何在if语句中回显PHP和HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个if语句,仅当$ result37 = ncrteam的值时才需要显示一些代码,但是如何显示HTML和PHP代码呢?回声";无法正常工作并回显'';也行不通.

I have an if statement that only has to show some code if the value of $result37 = ncrteam... but how can I echo that HTML and PHP code? echo" "; is not working and echo ' '; Is also not working.

这是我的代码:

<?php
    if ($result37 === "ncrteam") {
?>
Status:<br>
    <select class="form-control" name="status" style="width: 300px">
        <?php
            while ($row15 = mysqli_fetch_assoc($result15)):; ?>
                <option selected value=\"<?php echo $row15['status'];?>\"><?php echo $row15['status'];?></option>
        <?php endwhile;?>
        <?php while ($row16 = mysqli_fetch_assoc($result16)):; ?>
                <option value=\"<?php echo $row16['statusname'];?>\"><?php echo $row16['statusname'];?></option>
        <?php endwhile;?>
    </select>
<?php
    }
?>

推荐答案

这不是一个完整答案,因为目前尚不清楚您到底想做什么,但是您的问题看起来像是How do I build html based on values of my php variables,我会尽力回答

This is not a complete answer, because it is unclear what exactly you are trying to do, but your question looks something like How do I build html based on values of my php variables and I will try to answer it as best I can

鉴于我从您的问题中获得的信息有限,我认为这是您要尝试做的事情:

With the limited information I have from your question, I think this is the kind of thing you are trying to do:

 <?php

 ... 
 $html = "";
 if ($result37 === "ncrteam") {
    while ($row15 = mysqli_fetch_assoc($result15))
    {
         $html .= "<option value=".$row15['status'].">";
    }
 }
 ?>

<html>
    <body>
        ...
        <select>
            <?php echo $html; ?>
        </select>
        ...
    </body>
</html>

这篇关于如何在if语句中回显PHP和HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆