user3301042
user3301042

Reputation: 352

using three while loops consecutively

$connect = mysqli......
$command1 = mysqli....
while($row = mysqli_fetch_array($command1)){
    echo $row[];

    $command2 = mysqli......
    while($row = mysqli_fetch_array($command2)){
    echo $row[''];

    }
}

this code line works properly.

but when i add an another while loop all logic falls.

$connect = mysqli......
$command1 = mysqli....
while($row = mysqli_fetch_array($command1)){
  echo $row[];

  $command2 = mysqli.....
  while($row = mysqli_fetch_array($command2)){
    echo $row[''];

    $command3 = mysqli......
    while($row = mysqli_fetch_array($command3)){
      echo $row[''];

    } 
  }
}

.... it press first, second and thirds echos to screen. then i am expecting it to return $command2 again but it retuns to $command1, presses echo and stops.

why it returns to first while instead of second while?

what is the difference?

Upvotes: 2

Views: 84

Answers (1)

Peyman Mohamadpour
Peyman Mohamadpour

Reputation: 17944

UPDATE

That's better you change your code like this:

$connect = mysqli...
$command1 = mysqli...
$command2 = mysqli...
$command3 = mysqli...
while( $row1 = mysqli_fetch_array( $command1 ) ){
  while( $row2 = mysqli_fetch_array( $command2 ) ){
    while( $row3 = mysqli_fetch_array( $command3 ) ){
    }
  }
}

I believe that would solve the problem

Upvotes: 1

Related Questions