Q:

Why does it enter the same id in the database instead of entering one by one each?

Hy,
I want to ban a user when the admin clicks on "bannir" (this will collect the id of the user and put "banned" at 1 in the database)
to print the user informations I'm using a while loop, but when I try to collect the id of the user where in the html tag with the class "idUser", it is always sending the first id and I don't know why..
image of membership area
<div>
<table class="table">
  <thead>
    <tr>
      <th>#</th>
      <th>Prénom</th>
      <th>Nom</th>
      <th>Email</th>
      <th>Admin</th>
      <th>Banni</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    <?php while($userInfo = $req->fetch()){?>
    <tr>
      <td class="idUser"><?= $userInfo['id_user'] ?></td>
      <td><?= $userInfo['last_name'] ?></td>
      <td><?= $userInfo['first_name'] ?></td>
      <td><?= $userInfo['email'] ?></td>
      <td><?php if($userInfo['admin'] == 1){ ?>  
          <img src="../img/ok.png">
        <?php } else { ?> 
          <img src="../img/no.png">
          <?php } ?></td>
      <td><?php if($userInfo['banned'] == 1){ ?> 
        <strong style="color:#E04949;">OUI</strong>
        <?php } else { ?> 
        <strong style="color:#6AC259;">NON</strong>
          <?php } ?></td>
      <td><a href="#">Modifier</a> | <a href="#" class="banMemberJquery"><?php if($userInfo["banned"] == 0){ ?> Bannir <?php }else{ ?> Débannir <?php } ?></a></td>
    </tr>
  <?php } ?>
  </tbody>
</table>

<script type="text/javascript">

$('.banMemberJquery').click(function(){

  var idUser = $( ".idUser" ).html();

  alert('Utilisateur Numero ' + idUser + ' banni avec succès.');

  $.ajax({
  url:"banMemberRequest.php",
  data:'idUser='+idUser,

  }).done(function(data){

  $('#result').html(data); 
});

});

PS : When I click on "bannir", the request in the file "banMemberRequest.php" is working correctly. 
Thank's in advance for helping

A:

The issue is because you're selecting all .idUser elements. Calling html() on that will only read the HTML of the first one in that collection.
To fix this you need to use DOM traversal to find only the .idUser element which is related to the .banMemberJquery element which was clicked. To do that you can use closest() and find(), like this:
$('.banMemberJquery').click(function() {
  var idUser = $(this).closest('tr').find('.idUser').text(); // note text(), not html()

  $.ajax({
    url: 'banMemberRequest.php',
    data: { idUser: idUser },
  }).done(function(data) {
    $('#result').html(data); 
  });
});

