2

尝试使用 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>
4

2 回答 2

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

请试试这个

希望对你有帮助

于 2012-08-09T07:39:11.230 回答
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>';
?> 
于 2012-08-09T07:40:49.307 回答