Julian Posted April 26, 2010 Share Posted April 26, 2010 Hello guys I'm getting the results from my database using do {} while, this is working fine. What I want to is put a number starting from 1 to each result, each record has it's unique key but I want to start from 1 with the results, example: do { echo "Number # Here" . $row_name['name'] . "<br />"; } while ($row_name = mysql_fetch_assoc($name)); Output "Number 1 Here" John "Number 2 Here" Teresa "Number 3 Here" Jamie Quote Link to comment https://forums.phpfreaks.com/topic/199848-how-to-create-a-line-number-on-the-fly/ Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 You don't want to do a "do" loop, a normal while is needed, otherwise $row_name will be null the first time. We can do it 2 ways, either use a while with a counter, or a for loop. I'll give the for loop example: for($i = 1; $row_name = mysql_fetch_assoc($name); $i++) { echo "Number $i Here" . $row_name['name'] . "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/199848-how-to-create-a-line-number-on-the-fly/#findComment-1049002 Share on other sites More sharing options...
Julian Posted April 26, 2010 Author Share Posted April 26, 2010 Thanks... this worked fine! Quote Link to comment https://forums.phpfreaks.com/topic/199848-how-to-create-a-line-number-on-the-fly/#findComment-1049006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.