第二栏没有显示

时间:2016-01-28 20:50:47

标签: php html

我有一段代码,我从数据库中提取数据并在页面上显示数据,分为两列。第一列显示,但第二列没有显示......代码如下:

$stmt = $db->prepare('SELECT InfoID, Titel, Inhoud FROM Informatie WHERE Pagina = "Behandelingen";');
$stmt -> execute();
$count = $stmt->rowCount();
if ($count == 1) {
echo '<div class="col-sm-10"><div class="panel panel-default">';
while ($row = $stmt->fetch()) {
    $titel = $row['Titel'];
    $inhoud = $row['Inhoud'];
    echo "<div class='panel-heading'><b>$titel</b></div>";
    echo "<div class='panel-body'>$inhoud</div>";
}
} else if($count >= 2) {
echo '<div class="col-sm-5">';
while ($row = $stmt->fetch()) {
    $titel = $row['Titel'];
    $inhoud = $row['Inhoud'];
    $infoID = $row['InfoID'];
    if ($infoID % 2 != 0) {
    echo "<div class='panel panel-default'>";
    echo "<div class='panel-heading'><b>$titel</b></div>";
    echo "<div class='panel-body'>$inhoud</div></div>";
}}
echo "</div><div class='col-sm-5'>";
while ($row = $stmt->fetch()) {
    $titel = $row['Titel'];
    $inhoud = $row['Inhoud'];
    $infoID = $row['InfoID'];
    if ($infoID % 2 == 0) {
    echo "<div class='panel panel-default'>";
    echo "<div class='panel-heading'><b>$titel</b></div>";
    echo "<div class='panel-body'>$inhoud</div></div>";
}}
echo"</div>";
}

如果有人想亲眼看看我的意思,你可以看到有问题的页面here

2 个答案:

答案 0 :(得分:0)

当我检查页面元素时,它似乎没有显示您为第二列回显的任何代码,它显示了最初的<div class='col-sm-5'></div>

另外,检查你的报价。我不确定它是否会产生影响,但它们在第二个初始回声中的差异与第一列中的第一个回声不同。

答案 1 :(得分:0)

第一个while ($row = $stmt->fetch())将遍历所有结果,并且在第二个while语句中将无法获取

$stmt = $db->prepare('SELECT InfoID, Titel, Inhoud FROM Informatie WHERE Pagina = "Behandelingen";');
$stmt -> execute();
$count = $stmt->rowCount();
if ($count == 1) {
    echo '<div class="col-sm-10"><div class="panel panel-default">';
    while ($row = $stmt->fetch()) {
        $titel = $row['Titel'];
        $inhoud = $row['Inhoud'];
        echo "<div class='panel-heading'><b>$titel</b></div>";
        echo "<div class='panel-body'>$inhoud</div>";
    }
} 
else if($count >= 2) {
    while ($row = $stmt->fetch()) {
        echo '<div class="col-sm-5">';
        $titel = $row['Titel'];
        $inhoud = $row['Inhoud'];
        $infoID = $row['InfoID'];
        if ($infoID % 2 != 0) {
            echo "<div class='panel panel-default'>";
            echo "<div class='panel-heading'><b>$titel</b></div>";
            echo "<div class='panel-body'>$inhoud</div></div>";
        }
        echo"</div>";
    }
}