意外的文件结尾和解决时不起作用


unexpected end of file and when solved doesn't work

这段代码给了我意想不到的文件结尾。我不知道怎么了。当我最后更改:时,错误问题消失了,但代码停止工作。它不再为我获取任何数据。此外,当我将代码复制到 jsfiddle 时,我得到了结束</section>标签和结束</div>标签,倒数第二的红色。知道为什么吗? 标签的顺序是否错误?

<?php while ($r = $q->fetch()): ?>

这是我正在处理的完整代码,如果有人感兴趣或有任何线索。

<section id="portfolio" class="two">
  <div class="container">
    <header>
      <h2>Latest Answers</h2>
    </header>
    <?php
require_once 'dbconfig.php';
try {
    $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    echo "Connected to $dbname at $host successfully.";
    $sql = "SELECT * 
            FROM as_questions 
            WHERE Answer IS NOT NULL and Answer != ''";

    $q = $conn->query($sql);
    $q->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $pe) {
    die("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>
      <table>
        <?php while ($r = $q->fetch()): ?>
          <div class="span3 tiny">
            <div class="pricing-table-header-tiny">
              <h1 id="h1q"><?php echo htmlspecialchars($r['Question']);?></h1>

            </div>
            <div>
              <div class="pricing-table-features">
                <p id="dassp2">
                  <?php echo htmlspecialchars($r['Answer'])?>
                </p>
              </div>
              <div>
                <p id="Dassp">Answered by:
                  <?php echo htmlspecialchars($r['Doctor'])?>
                </p>
              </div>
            </div>
          </div>
  </div>
  <div id="qref">
    <a href="#" id="s">More Answers</a>
  </div>
</section>
while (expr):
    statement
    ...
endwhile;

您需要闭环 - 更多信息在这里 http://php.net/manual/en/control-structures.while.php