Jump to content

Counter


emediastudios

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/215944-counter/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/215944-counter/#findComment-1122499
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.