0

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>";
2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ﻼim
0

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.

Edited by ﻼim: codes. Ϋ

0

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. Ϋ

0

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

no problem ceeandcee. Ϋ
thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.