当我输入PHP代码时,html标签消失了

时间:2014-02-08 00:43:38

标签: php html-table

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

<?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>

2 个答案:

答案 0 :(得分:2)

我看到两个错误的可能性

  • PDO::query失败时会返回false,但您不会测试返回值。如果$query为false,则fetch部分将失败并显示错误消息并停止脚本。
  • 另一个可能是,您没有名为nick
  • 的列

答案 1 :(得分:0)

以下是在HTML中使用PHP的示例:

<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。