Reputation: 79
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
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
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