CODE SEEK
CODE SEEK

Reputation: 79

While loop wrap values using a single Div

Trying to print posts from database using While loop, Not able to wrap all posts in single DIV tag.

Code:

 <?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 } ?>

Need the Output to be:

<div>
posts
posts
posts
posts
</div>

Upvotes: 2

Views: 336

Answers (2)

Jalpesh Patel
Jalpesh Patel

Reputation: 3188

<?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

Please try this

I hope it helps you

Upvotes: 3

Mihai Matei
Mihai Matei

Reputation: 24276

<?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>';
?> 

Upvotes: 1

Related Questions