虽然循环不适用于 php

While loop doesn't work on php

<?php

if (!($database = mysqli_connect("localhost", "root", "","gem"))) {                           
    die( "Connexion non possible à la base de données." );
}

$requete = "SELECT nom_eta FROM etablissements ";
$query = "SELECT * FROM formations";

if ( !( $result = mysqli_query($database, $requete) ) OR !( $resulta = mysqli_query($database, $query) )) {
    print( "Impossible d'exécuter la requête! <br />" );
    die( mysqli_error($database) );
}

while ($row = mysqli_fetch_assoc($result) ) {
    $data=$row;
?>
    <a href="#"><?php echo $data['nom_eta'];?></a>
<?php
    while ($ligne = mysqli_fetch_assoc($resulta) ){
        $donnee=$ligne;
        if($data['nom_eta']==$donnee['nom_eta']) {
        ?>
            <ul>
                <a href="#"><?php echo $donnee['formation'];?></a>
            </ul>
        <?php
        }
    } 
}
?>

我的问题是,在 ENSAT 和 ENCGT 下应该显示其他数据,但在重新执行 WHILE-LOOP 时出现某种问题..

你不应该嵌套 while,而是 运行 之前的第二个并将结果分配给一个数组,然后你可以在另一个 while

中循环数组
<?php
if ( !( $database = mysqli_connect( "localhost","root", "","gem")))                           
  die( "Connexion non possible à la base de données." );
$requete = "SELECT nom_eta FROM etablissements ";
$query = "SELECT * FROM formations";
if ( !( $result = mysqli_query($database, $requete) ) OR !( $resulta = mysqli_query($database, $query) )) {
  print( "Impossible d'exécuter la requête! <br />" );
  die( mysqli_error($database) );
}

$ligne = array();
while ($row = mysqli_fetch_assoc($resulta)) {
  $ligne[] = $row;
}

while ($row = mysqli_fetch_assoc($result) ){
  $data=$row;
  ?><a href="#"><?php echo $data['nom_eta'];?></a><?php

  foreach ($ligne as $donee) {

    if($data['nom_eta']==$donnee['nom_eta']){
      ?><ul><a href="#"><?php echo $donnee['formation'];?></a><?php ?></ul><?php
    }
  } 
}
?>