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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.