这段代码给了我意想不到的文件结尾。我不知道出了什么问题。当我更改:最后,错误问题消失了,但代码停止工作。它不再向我提取任何数据。此外,当我将代码复制到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>
答案 0 :(得分:1)
while (expr):
statement
...
endwhile;
您需要关闭循环 - 更多信息http://php.net/manual/en/control-structures.while.php