nested while loop – what I’m doing wrong?

The question is really simple I guess, but I can’t figure it out what I’m doing wrong.
I’ve a nested while loop and two rows.
The result should be:

ManU - Arsenal
Chelsea - Liverpool
ManCity - Everton
Tottenham - Fulham

but what I got is this:

ManU - Arsenal
Chelsea - 
ManCity -
Tottenham -

This is the code:

$row1 = array('ManU','Chelsea','ManCity', 'Tottenham');
$row2 = array('Arsenal','Liverpool','Everton', 'Fulham');

    $i = 0;
    $j = 0;

    echo "<table>";
    while($i < count($row1)){
        $a = $row1[$i];
        echo "<tr><td>".$a." - ";

        while($j < count($row2)){
            $b = $row2[$j];
            echo $b."</td></tr>";   
    echo "</table>";

The thing is it must be a nested while loop because in fact I’m using SQL, and this is just a simplified version of the problem (rows instead of db table rows), on the other version the problem is the same, so it’s not a SQL problem, i think. Please help!

Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.