There are multiple ways to increase the value of a variable with 1:
Arithmetic operators:
Incrementing/Decrementing Operators:
The location of the incrementing / decrementing operator determines when the calculation is executed. When using a pre-increment (++$a;
), the variable is incremented, then returned. When using a post-increment ($a++;
), the variable is returned first, and then incremented.
Example:
$a = 5;
echo $a++; // echoes '5'
echo $a; // echoes '6'
$a = 5;
echo ++$a; // echoes '6'
echo $a; // still echoes '6'
Of course, if you don't echo the value, it doesn't matter if you use $a++
or ++$a
.
Returning to your case, you can use the following code:
$counter = 1;
while($comment = mysql_fetch_assoc($sql_comment)) {
echo '#' . $counter++ . ','; // First echo $counter, then increment it
echo $comment['content'];
echo "<br />";
}
By the way, you can use MySQL instead of PHP to count the comments as well.