In your for
loop, echo a DIV
instead of just echoing the number.
for ($i = 1; $i <= $postCounter; $i++) {
echo "<div>$i</div>";
}
Question
CODE :
$result= mysql_query ("SELECT COUNT(post_id) AS postCounter FROM headlines WHERE user_id= '$_SESSION[user_id]' ");
$numrows = mysql_num_rows ($result);
if ($numrows!=0){
while ($row = mysql_fetch_array ($result))
$postCounter = $row['postCounter'];
for ($i=1; $i<=$postCounter; $i++){
echo "$i";
}
}
Now, what I want to know is "How could I use for-loop to echo div's depending on the COUNT result?"
So if $postCounter
above was "4" I need to display 4 divs for it .
Solution
In your for
loop, echo a DIV
instead of just echoing the number.
for ($i = 1; $i <= $postCounter; $i++) {
echo "<div>$i</div>";
}
OTHER TIPS
An other way you can do by FOREACH to embed html into php
<ul>
<?php foreach($postcounter as $post) { ?>
<li><?php echo $post; ?></li>
<?php } ?>
</ul>
Hope this help