2014-02-08 46 views
-1

这对我来说是个谜。我在这里有一个Html代码块,并且我希望记录可以使用php循环使用。现在,当我添加一个php代码时,即使在视图源代码中,所有下面的php都没有了。我不知道发生了什么。当我把php放在最下面的时候,所有东西都显示出来了,当我把php放在中间时,只有上面的html出现在视图源中。当我放置一个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> 
+0

没有源代码,你能提供吗? – tomirons

+0

请显示相应的HTML/PHP代码。没有任何显示,我们无法提供帮助。 –

+0

ops。抱歉。^_^ – yul757

回答

2

我看到两个错误possibilites失败

  • PDO::query回报false,但你不测试返回值。如果$query为假,则fetch部件将失败,并显示错误消息并停止脚本。
  • 另外一个可能是,你没有一个叫nick
+0

这也是我的第一个想法:) – Shocked

+0

我只有3行PHP代码在这里,我只是测试一个while循环,但不使用while循环。 – yul757

+0

感谢您的线索。^_ ^它的我的PHP连接。我忘了我在不同的位置。谢谢。我会注意到这个错误。解决了。 – yul757

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。

相关问题