Page 1 of 1

Simple Counter

Posted: Tue May 18, 2004 12:35 am
by ankurdave
My problem is very simple
In the result i got the all values in tables but my counter always shows value 1 in all the fields
My code is as follows

Code: Select all

<?php
while ($row = mysql_fetch_object($result))
{
    $counter = 1;
    $value = $row -> innovatorid;
    $result1 = mysql_query("SELECT * FROM innovator WHERE innovatorid="$value"") or die("Query 2 Wrong");
    $total1 = mysql_num_rows($result1); 
    while ($row1 = mysql_fetch_object($result1))
   {
        print("<tr>"); 
        print("<td align="center">" . $counter++ . "</td>"); 
        print("<td align="center"><a href="innovators.php?         innovatorid=" . $row1 -> innovatorid . "">" . $row1 -> fname . "</a></td>");
        print("<td align="center"><a target="New Window" href="http:\cases" . $row1 -> linkpage . "">" . $row1 -> linkpage . "</a></td>");
        print("</tr>");
    } 
    $counter = $counter + 1;
	// 	echo "$counter";
} 

?>
The problem is in the line

Code: Select all

<?php
        print("<td align="center">" . $counter++ . "</td>"); 

?>
[/b]

It always shows 1 in each column

Posted: Tue May 18, 2004 1:00 am
by feyd
($counter++) maybe..

Posted: Tue May 18, 2004 1:47 am
by ankurdave
I do it in this way then it show 2 in all column

Code: Select all

<?php

 $counter = $counter+1;
 print("<td align="center">" . $counter . "</td>"); 

?>
it show 2 in all column

Posted: Tue May 18, 2004 2:19 am
by feyd
okay.. looking at your script more closely.. you seem to be only returning 1 object for the second query.

Since you have $counter = 1, inside the loop.. it gets reset for each one found.

so.. pull the $counter=1 bit out of the loop.

Posted: Wed May 19, 2004 8:39 am
by ankurdave
thnx
I done it