Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.