emediastudios Posted October 15, 2010 Share Posted October 15, 2010 Hey all. Have a question, im still learning but what i am trying to do is make the number 1 add 1 to itself and repeat in the loop so, 1 2, 3, 4, 5, 6 ect...What am i doing wrong. $result = mysql_query("SELECT * FROM comments WHERE quoteid = ".$_REQUEST['quoteid'].""); while($row=mysql_fetch_array($result)){ $date = $row[date]; $name = $row[name]; $email = $row[email]; $quoteid = $row[quoteid]; $comment = stripslashes($row[comment]); $commentid = $row[commentid]; $counter = 1; $counted = $counter++; $resultb = mysql_query("SELECT * FROM quotes WHERE quoteid= '$quoteid'") or die(mysql_error()); while($link=mysql_fetch_array($resultb)){ $artist = $link[artist]; $song = $link[song]; } echo'<table border="0" cellpadding="0" cellspacing="0"><tr> <td rowspan="3" align="center"><span class="commentNumber">'.$counted.'</span></td> Quote Link to comment https://forums.phpfreaks.com/topic/215944-counter/ Share on other sites More sharing options...
premiso Posted October 15, 2010 Share Posted October 15, 2010 Pretty basic, but your main issue is that you keep reseting the counter to be 1 each iteration. $result = mysql_query("SELECT * FROM comments WHERE quoteid = ".$_REQUEST['quoteid'].""); $counter = 1; while($row=mysql_fetch_array($result)){ $date = $row[date]; $name = $row[name]; $email = $row[email]; $quoteid = $row[quoteid]; $comment = stripslashes($row[comment]); $commentid = $row[commentid]; $counted = $counter++; Moving the $counter variable outside of the loop will prevent this behavior from resetting. Quote Link to comment https://forums.phpfreaks.com/topic/215944-counter/#findComment-1122499 Share on other sites More sharing options...
emediastudios Posted October 15, 2010 Author Share Posted October 15, 2010 Thanks, im tired. fixed. Quote Link to comment https://forums.phpfreaks.com/topic/215944-counter/#findComment-1122508 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.