首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >当我把一段PHP代码放入html标签中时

当我把一段PHP代码放入html标签中时
EN

Stack Overflow用户
提问于 2014-02-08 08:43:38
回答 1查看 1.2K关注 0票数 -1

这对我来说是个谜。我这里有一个Html代码块,我希望记录循环使用PHP的表。现在,当我添加PHP代码时,PHP下面的所有内容都消失了,甚至在视图源代码中也是如此。我想知道发生了什么事。当我将PHP放在底部时,所有内容都会显示出来,当我把PHP放在中间时,视图源代码中只会显示上面的html。

代码语言:javascript
复制
<?php include('incl/connect.php'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
    <title>Admin</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <link rel="shortcut icon" href="../favicon.ico"> 
    <link rel="stylesheet" type="text/css" href="../css/reset.css">
    <link rel="stylesheet" type="text/css" href="../css/style2.css">
    <link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700,300,300italic' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="../css/tables.css">
    <!--[if lt IE 9]>
    <style>
    .content{
        height: auto;
        margin: 0;
    }
    .content div {
        position: relative;
    }
    </style>
    <![endif]-->
</head>
<body>
    <div class="container">
        <section class="tabs">
            <input id="tab-1" type="radio" name="radio-set" class="tab-selector-1" checked="checked" />
            <label for="tab-1" class="tab-label-1">Home</label>

            <input id="tab-2" type="radio" name="radio-set" class="tab-selector-2" />
            <label for="tab-2" class="tab-label-2">Repairs</label>

            <input id="tab-3" type="radio" name="radio-set" class="tab-selector-3" />
            <label for="tab-3" class="tab-label-3">yet</label>

            <input id="tab-4" type="radio" name="radio-set" class="tab-selector-4" />
            <label for="tab-4" class="tab-label-4">yet</label>

            <div class="clear-shadow"></div>

            <div class="content">
                <div class="content-1">
                    <p>Search <input type="search" placeholder="Search"></p>
                    <input type="checkbox" checked="checked">All
                    <input type="checkbox" >Female only
                    <input type="checkbox" >Male only
                    <table cellspacing='0'> <!-- cellspacing='0' is important, must stay -->
                        <!-- Table Header -->
                        <thead>
                            <tr>
                                <th>Username</th>
                                <th>Fullname</th>
                                <th>Status?</th>
                                <th>Remaining time</th>
                                <th>Expires</th>
                                <th>Active</th>
                            </tr>
                        </thead>
                        <!-- Table Header -->

                        <!-- Table Body -->
                        <tbody>
                            <?php $query = $conn->query("SELECT * FROM client"); 
$member = $query->fetch(PDO::FETCH_ASSOC); ?>
                            <tr>
                                <td><?php echo $member['nick']; ?></td>
                                <td>here </td>
                                <td></td>

                            </tr><!-- Table Row -->

                        </tbody>
                        <!-- Table Body -->

                    </table>
                </div><!--- content-1 end -->
                <div class="content-2">
                   <h2>Repairs</h2>

                </div><!-- content- end-->
                <div class="content-3">
                    <h2>soon</h2>
                    <p></p>
                </div><!--content-3 end-->
                <div class="content-4">
                    <h2>sooon</h2>
                    <p></p>
                </div><!--- content-4 end -->
            </div>
        </section>
    </div>
</body>
</html>
EN

回答 1

Stack Overflow用户

发布于 2014-02-08 08:50:30

下面是一个在HTML中使用PHP的示例:

代码语言:javascript
复制
<table style="margin-top: 5px; margin-bottom: 5px;" width="100%">
    <tbody>
        <?php foreach ($this->masters as $val) { ?>
            <tr>
                <td width="64px" style="padding: 1px;">

                    <img style="margin-left: 20px;" alt="" src="<?php echo $this->url; ?>img/palm_tree_purple.png"></img>

                </td>
                <td align="left">
                    <h5 style="margin: 1px;"><?php echo $val; ?></h5>
                </td>
            </tr>
        <?php } ?>
    </tbody>
</table>

当你想使用PHP时,你可以用PHP标签<?php打开它,然后当你使用完PHP之后,你可以用?>关闭它。然后,您可以继续使用HTML。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21640345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档