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

Recommended Answers

All 2 Replies

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?

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.. :(

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.