What I am trying to do is to run a query in my database and output a table to a php file. If the query yields 10 resuts or rows, I would like the far left column to read 1,2,3,4,5,6,7,8,9,10.

What happens now is it outputs all 1's in the first column and not 1,2,3, etc.

Any ideas? Any help would be appreciated!

echo "<table width='350' border='1' cellspacing='0' cellpadding='1' bgcolor='ffffff'>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td width='20' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>"; 
 	$n="0";
 	echo "".++$n;
	echo "</td><td width='170' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>"; 
	echo $row['Last'];
	echo ", ";
	echo $row['First'];
	echo "</td>
}
echo "</table>";

What I am trying to do is to run a query in my database and output a table to a php file. If the query yields 10 resuts or rows, I would like the far left column to read 1,2,3,4,5,6,7,8,9,10.

What happens now is it outputs all 1's in the first column and not 1,2,3, etc.

Any ideas? Any help would be appreciated!

echo "<table width='350' border='1' cellspacing='0' cellpadding='1' bgcolor='ffffff'>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td width='20' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>"; 
 	[B]$n="0";[/B]
 	[B]echo "".++$n;[/B]
	echo "</td><td width='170' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>"; 
	echo $row['Last'];
	echo ", ";
	echo $row['First'];
	echo "</td>
}
echo "</table>";

try to replace
echo "".++$n;
to this
echo "".$n++;

and

$n = "0";
to this
$n = 0;

it is better to make the $n an integer variable type than a string.
hope this helps!
good Luck! Ϋ


and ooopppss!

do put the $n initialization

($n = 0;)

out of the while loop because in your code it will always have the value of zero (0) before incrementing ti one after a single loop.

What I am trying to do is to run a query in my database and output a table to a php file. If the query yields 10 resuts or rows, I would like the far left column to read 1,2,3,4,5,6,7,8,9,10.

What happens now is it outputs all 1's in the first column and not 1,2,3, etc.

Any ideas? Any help would be appreciated!

echo "<table width='350' border='1' cellspacing='0' cellpadding='1' bgcolor='ffffff'>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td width='20' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>"; 
 	$n="0";
 	echo "".++$n;
	echo "</td><td width='170' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>"; 
	echo $row['Last'];
	echo ", ";
	echo $row['First'];
	echo "</td>
}
echo "</table>";

have this code rather :

echo "<table width='350' border='1' cellspacing='0' cellpadding='1' bgcolor='ffffff'>";
 $n = 0;
 // not sure if having  $n = "0"; will do an increment
 
while($row = mysql_fetch_array($result)) {
	echo "<tr><td width='20' bgcolor='ffffff' align='center'><font face='arial' size='2' color='000000'>"; 

 	echo "".$n++;
	echo "</td><td width='170' bgcolor='ffffff' align='left'><font face='arial' size='2' color='000000'>"; 
	echo $row['Last'];
	echo ", ";
	echo $row['First'];
	echo "</td>";
}

echo "</table>";

happy day ahead!

and please don't forget to mark this thread as solved if your problem is already solved. Ϋ

Awesome! Thanks so much...this is great!

Awesome! Thanks so much...this is great!

no problem ceeandcee. Ϋ
thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.