I need help with an item counter on my site that will tell the user how many items are in a single category. Items will be added frequently, so there needs to be a variable representing the # of items. So I have made $counter. When each item is added, I simply do $counter++ to increment the counter by 1 item. I then print out the $counter variable with echo and it is okay. However, the problem is, I want to echo the $counter ABOVE the increments $counter++. The problem is that it does not include these increments because they come after the echo. So the echo doesn't update with the counters. If echo comes after the $counter++'s, it works, but I can't have it like that.
Here is what works, but echo is on the bottom, I need it on the top:
Code: Select all
<?php $counter=0; ?>
<?php $counter++; ?>
<?php $counter++; ?>
<?php $counter++; ?>
<?php echo $counter; ?>Code: Select all
<?php
$counter=0;
echo $counter; ?>
<?php $counter++; ?>
<?php $counter++; ?>
<?php $counter++; ?>