for loop problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guyfromfl
Forum Newbie
Posts: 4
Joined: Wed Aug 10, 2005 1:05 pm
Location: florida

for loop problem

Post 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);
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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++){
guyfromfl
Forum Newbie
Posts: 4
Joined: Wed Aug 10, 2005 1:05 pm
Location: florida

Post by guyfromfl »

right before the loop i have this:

$f = mysql_num_fields($result);
guyfromfl
Forum Newbie
Posts: 4
Joined: Wed Aug 10, 2005 1:05 pm
Location: florida

Post by guyfromfl »

Code: Select all

$f =  mysql_num_fields($result);
sorry :wink:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

or just simple do:

Code: Select all

for($i = 0; $i < $f; $i++)
guyfromfl
Forum Newbie
Posts: 4
Joined: Wed Aug 10, 2005 1:05 pm
Location: florida

Post by guyfromfl »

thanks guys BIG help...the $i<$f thing fixed the problem
Post Reply