将循环代码中的PHP内容放在DIV中

时间:2017-04-14 17:54:23

标签: php html css mysql

所以我想将这个DIV类应用于这些PHP项目。 这就是我所拥有的,我知道它不起作用,但对于我想要实现的目标是正确的。

我不能单独为每个人添加课程,因为我希望整个内容都在一个div内。

希望有意义,谢谢!

<?php 

while($campaigns= mysqli_fetch_assoc($result)){
    <div class="feeditem">;
    echo "<div class='field'>".$test['part0']."</div>";
    echo "<div class='field'>".$test['part1']."</div>";
    echo "<div class='field'>".$test['part2']."</div>";
    echo "<div class='field'>".$test['part3']."</div>";
    echo "<div class='field'>".$test['part4']."</div>";
    echo "<div class='field'>".$test['part5']."</div>";
    echo "<div class='field'>".$test['part6']."</div>";
    </div>;
}

?>

2 个答案:

答案 0 :(得分:0)

您应该使用一个IDE,它会为您提供语法问题的错误...您没有在echo "";语句中包含所有html代码。

while ($campaigns = mysqli_fetch_assoc($result)) {
        echo '<div class="feeditem">';
        echo "<div class='field'>" . $test['part0'] . "</div>";
        echo "<div class='field'>" . $test['part1'] . "</div>";
        echo "<div class='field'>" . $test['part2'] . "</div>";
        echo "<div class='field'>" . $test['part3'] . "</div>";
        echo "<div class='field'>" . $test['part4'] . "</div>";
        echo "<div class='field'>" . $test['part5'] . "</div>";
        echo "<div class='field'>" . $test['part6'] . "</div>";
        echo '</div>';
}

答案 1 :(得分:0)

我相信这是你想要完成的事情:

<?php
echo '<div class="feeditem">';
while($campaigns = mysqli_fetch_assoc($result)){
    echo"<div class='field'>".$test['part0']."</div>";
    echo"<div class='field'>".$test['part1']."</div>";
    echo"<div class='field'>".$test['part2']."</div>";
    echo"<div class='field'>".$test['part3']."</div>";
    echo"<div class='field'>".$test['part4']."</div>";
    echo"<div class='field'>".$test['part5']."</div>";
    echo"<div class='field'>".$test['part6']."</div>";
}
echo '</div>';