Page 1 of 1

for loop problem

Posted: Wed Aug 10, 2005 1:08 pm
by guyfromfl
I keep getting an undefined offset 21 on with this code: any suggestions?

if (mysql_num_rows($result) > 0) {
echo "<table cellpadding=1 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
for ($i = 0; $i <= $f; $i++){
echo "<td>";
echo $row[$i]; <--Error Line
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
}
else {
echo "No Rows Found!";
}
echo $i."found";
mysql_free_result($result);

Posted: Wed Aug 10, 2005 1:15 pm
by hawleyjr
Please use tages when posting.

In your loop you have a variable named 'f' not i.

Code: Select all

for ($i = 0; $i <= $f; $i++){

Code: Select all

for ($i = 0; $i <= $i; $i++){

Posted: Wed Aug 10, 2005 1:24 pm
by guyfromfl
right before the loop i have this:

$f = mysql_num_fields($result);

Posted: Wed Aug 10, 2005 1:25 pm
by guyfromfl

Code: Select all

$f =  mysql_num_fields($result);
sorry :wink:

Posted: Wed Aug 10, 2005 2:54 pm
by shiznatix
$f will start at 1 not 0 like $i will start at. so there is your undefined stuff...im perdy sure. make $i=1 instead of $i=0 and see what happens

Posted: Wed Aug 10, 2005 4:08 pm
by feyd
or just simple do:

Code: Select all

for($i = 0; $i < $f; $i++)

Posted: Wed Aug 10, 2005 6:57 pm
by guyfromfl
thanks guys BIG help...the $i<$f thing fixed the problem