Reputation: 77
<?php
$stmt = $db->query("SELECT * FROM table LIMIT 5");
foreach ($AnB as $aB): ?>
<a href="#">
<div>
<h6>Number here</h6>
<h5><?php echo $aB['title'] ?></h5>
</div>
</a>
<?php endforeach; ?>
As you can see, i used a LIMIT 5, i want to put a number on each loop, starting on number 1 till 5. How can i do it?
This is how it should be:
Upvotes: 0
Views: 150
Reputation: 330
<?php
$count = 1;
$stmt = $db->query("SELECT * FROM table LIMIT 5");
foreach ($AnB as $aB): ?>
<a href="#">
<div>
<h6><?php echo $count; ?></h6>
<h5><?php echo $aB['title'] ?></h5>
</div>
</a>
<?php $count++; endforeach; ?>
I used a variable to maintain the count. It will add 1 to the $count
variable each time it loops through the foreach
Upvotes: 6