添加CSS样式,这取决于mysql_fetch_array中的php IF语句

I want to add CCS style which depends on php IF statement. I have found something: changing the style inside "if" statement, but somehow it doesn`t work, maybe because of WHILE statement in my code.

<?php
$possible_lang_list = mysqli_query($con, 
'SELECT * FROM page WHERE title = "lang" ORDER BY name1 ASC');

while ($row = mysqli_fetch_array($possible_lang_list)) {
  echo '
      <div class="language" id="' . $row['name2'] . '">
      <p>' . $row['name1'] . '</p>
      </div>
  ';
}
?>

I want to display only div class="language" where $row['name2'] == $x, with possibility to display whole class "language" with JavaScript. Could anyone help?

I have tried:

 while ($row = mysqli_fetch_array($possible_lang_list)) {
  if ($row['name2'] == $x) {
  ?>
  <div style="display:block;">
  <?php } else {
  ?>
  <div style="display:none;">
  <?php
  echo '
      <div class="" id="' . $row['name2'] . '">
        <p>' . $row['name1'] . '</p>

      </div>
  </div>';
  }
}

now it is working:

while ($row = mysqli_fetch_array($possible_lang_list)) {
  if ($row['name2'] == $x) {
  ?>
  <div style="display:block;">
  <?php } else {
  ?>
  <div style="display:none;">
  <?php   }
  echo '
      <div class="" id="' . $row['name2'] . '">
        <p>' . $row['name1'] . '</p>

      </div>
  </div>';

}

Assign a style element with a true/false ternary, like below. Then just output it!

<?php

while ($row = mysqli_fetch_array($possible_lang_list)) {
  $class = ($row['name2'] == $x) ? 'language' : null;
  echo '
      <div class="'.$class.'" id="' . $row['name2'] . '">
      <p>' . $row['name1'] . '</p>
      </div>
  ';
}

And then:

Try this code :

while ($row = mysqli_fetch_array($possible_lang_list)) 
{
  if($row['name2'] == $x)
  { 
     echo '<div class="language" id="' . $row['name2'] . '"><p>' . $row['name1'] . '</p>
  </div>';
  }
  else
  {
    echo '<div class="" id="' . $row['name2'] . '"><p>' . $row['name1'] . '</p>
  </div>';
  }

}

Hope it will work