尝试使用While循环打印数据库中的帖子,无法将所有帖子包装在单个DIV标记中。
代码:
<?php
$sql="select posts from coder where 1=1 ";
$result= mysql_query($sql);
while($row=mysql_fetch_array($result))
{
?>
<div> -------- Wrapper DIV Starts
<span><?php echo $row['1']; ?></span> ------ loop and print all post inside Wrapper DIV
</div> -------- Wrapper DIV Ends
<?php } ?>
需要输出:
<div>
posts
posts
posts
posts
</div>
答案 0 :(得分:3)
<?php
$sql="select posts from coder where 1=1 ";
$result= mysql_query($sql);
?>
<div> -------- Wrapper DIV Starts
<?php while($row=mysql_fetch_array($result)) { ?>
<span><?php echo $row['1']; ?></span> ------ loop and print all post inside Wrapper DIV
<?php } ?>
</div> -------- Wrapper DIV Ends
请试试这个
我希望它可以帮到你
答案 1 :(得分:1)
<?php
$sql="select posts from coder where 1=1 ";
$result= mysql_query($sql);
echo '<div>';
while($row=mysql_fetch_array($result))
{
?>
<span><?php echo $row['posts']; ?></span>
<?php
}
echo '</div>';
?>