I have the following:
$counter = 1;
while($row= mysql_fetch_assoc($result)) {
$counter2 = $counter++;
echo($counter2 . $row['foo']);
}
Is there an easier way to get 1,2,3 etc for each result or is this the best way?
Thanks
You don't need $counter2. $counter++ is fine. You can even do it on the same line as the echo if you use preincrement instead of postincrement.
$counter = 0;
while($row= mysql_fetch_assoc($result)) {
echo(++$counter . $row['foo']);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With