-1

hello to all,
I wrote a foreach() loop and inside I added a variable which also increase but not as with the array that run in the foreach(), but somehow the for each also increases my variable:

$n = 0;
while($row = mysql_fetch_row($GetItems)){
       echo "$n<tr>";
            foreach($row as $cell){
                if(strstr($cell,"Images")){
                    echo "<td><img src='$cell' hight='150px' width='150px'><input name='storeid' type='hidden' value='$StoreArr[$n]'></td>";
                }
                else{
                    echo "<td><a href='".$_SERVER['PHP_SELF']."?ShowAct=true&Item=".$row['0']."&store=".$StoreArr[$n]."&OnBid=true'>$cell</a></td>";
                }
            }//end_foreach
            echo "</tr>\n";  
            $n++;
        }

the "$n" is givin me the next output : 0 1 0 1
and I planned it to be 0 0 1 1.

any help will be appreciated

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by loudstil
0

Hey.

I see nothing inside the foreach loop that would mess with your $n variable. It should only be incremented by one for each row in your MySQL query result.

The output you printed makes no sense. The only thing in that code that changes the $n variable, aside from when you initialize it, is the $n++ on line #13, and that only increments it.

Are you sure you posted the right code snippet?
Or am I misunderstanding something?

0

Thanks for the reaply,
yeah, I know its realy wired but the "$n" is effected also from the foreach() loop.

I tried to set it as a static variable but it didn't do the trick.. :(

This topic has been dead for over six months. 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.