title: Php show users data from mysql with dropdown list
body: <p><a href="https://i.stack.imgur.com/iPgis.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iPgis.png" alt="enter image description here"></a>i want to display users data in a table with the dropdown list , the first option shows all the users but when i click a name it still shows all users, i think i have some trouble in my ajax script because it deosn't seem to work</p>
  
  <p>this is the page where i display data :</p>
  
  <pre><code>&lt;?php   
  //load_data_select.php  
  $connect = mysqli_connect("localhost", "root", "ntr-ktb123", "absence");  
  function fill_emp($connect)  
  {  
    $output = '';  
    $sql = "SELECT * FROM employés";  
    $result = mysqli_query($connect, $sql);  
    while($row = mysqli_fetch_array($result))  
    {  
         $output = $output."'&lt;option value="'.$row["IdEmp"].'"&gt;'.$row["NomEmp"].'&lt;/option&gt;'";  
    }  
    return $output;  
   }  
  function fill_Abs($connect)  
  {  
    $output = '';  
    $sql = "SELECT NomEmp,PrénomEmp,DateD,DateF,CauseAbs,justifié
  FROM absence.absences
  WHERE 
  MONTH(DateF) = MONTH(NOW())
  AND
   YEAR(DateF) = YEAR(NOW());";
  
    $result = mysqli_query($connect, $sql); 
   echo "&lt;table&gt;
   &lt;tr&gt;
   &lt;th&gt;NomEmp&lt;/th&gt;
   &lt;th&gt;PrénomEmp&lt;/th&gt;
   &lt;th&gt;DateD&lt;/th&gt;
   &lt;th&gt;DateF&lt;/th&gt;
   &lt;th&gt;CauseAbs&lt;/th&gt;
   &lt;th&gt;justifié&lt;th&gt;
    &lt;/tr&gt;"; 
    while($row = mysqli_fetch_array($result))  
    {  
         echo "&lt;tr&gt;";
   echo "&lt;td&gt;" . $row['NomEmp'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['PrénomEmp'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['DateD'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['DateF'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['CauseAbs'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['justifié'] . "&lt;/td&gt;";
   echo "&lt;/tr&gt;";
     }  
     $output="&lt;/table&gt;";
     return $output;  
   }  
   ?&gt;  
   &lt;!DOCTYPE html&gt;  
   &lt;html&gt;  
    &lt;head&gt;  
         &lt;title&gt;Webslesson Tutorial | Multiple Image Upload&lt;/title&gt;  
         &lt;link rel="stylesheet" 
  
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" 
   /&gt;  
          &lt;script 
   src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt; 
   &lt;/script&gt;  
         &lt;script 
   src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"&gt; 
   &lt;/script&gt;  
         &lt;style&gt;
   table {
   width: 100%;
   border-collapse: collapse;
    }
  
  table, td, th {
  border: 1px solid black;
  padding: 5px;
  }
  
  th {text-align: left;}
  &lt;/style&gt;
   &lt;script&gt;  
   $(document).ready(function(){  
    $('#nom').change(function(){  
         var NomEmp = $(this).val();  
         $.ajax({  
              url:"usr.php",  
              method:"POST",  
              data:{NomEmp:NomEmp},  
              success:function(data){  
                   $('#show_Abs').html(data);  
              }  
         });  
    });  
   });  
   &lt;/script&gt; 
    &lt;/head&gt;  
    &lt;body&gt;  
         &lt;br /&gt;&lt;br /&gt;  
         &lt;div class="container"&gt;  
              &lt;h3&gt;  
                &lt;label for="nom"&gt;Selectionnez le nom de l'employé &lt;/label&gt;
              &lt;/br&gt;&lt;/br&gt;
                   &lt;select name="nom" id="nom"&gt;  
                        &lt;option value=""&gt;Tout les employés&lt;/option&gt; 
                        &lt;?php echo fill_emp($connect); ?&gt;  
                   &lt;/select&gt;  
                   &lt;br /&gt;&lt;br /&gt; &lt;br /&gt; 
                   &lt;div class="row" id="show_Abs"&gt;  
                        &lt;?php echo fill_Abs($connect);?&gt;  
                   &lt;/div&gt;  
              &lt;/h3&gt;  
         &lt;/div&gt;  
    &lt;/body&gt;  
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is the usr.php : </p>
  
  <pre><code> &lt;?php  
   //load_data.php  
   $connect = mysqli_connect("localhost", "root", "ntr-ktb123", "absence");  
   $output = '';  
   if(isset($_POST["NomEmp"]))  
   {  
    if($_POST["NomEmp"] != '')  
    {  
         $sql = "SELECT NomEmp,PrénomEmp,DateD,DateF,CauseAbs,justifié
  FROM absence.absences
  WHERE 
  MONTH(DateF) = MONTH(NOW())
  AND
  YEAR(DateF) = YEAR(NOW()) WHERE NomEmp = '".$_POST["NomEmp"]."'";  
    }  
    else  
    {  
         $sql = "SELECT NomEmp,PrénomEmp,DateD,DateF,CauseAbs,justifié
  FROM absence.absences
  WHERE 
  MONTH(DateF) = MONTH(NOW())
  AND
   YEAR(DateF) = YEAR(NOW());";  
    }  
    $result = mysqli_query($connect, $sql);  
     $output="&lt;table&gt;
   &lt;tr&gt;
   &lt;th&gt;NomEmp&lt;/th&gt;
   &lt;th&gt;PrénomEmp&lt;/th&gt;
   &lt;th&gt;DateD&lt;/th&gt;
   &lt;th&gt;DateF&lt;/th&gt;
   &lt;th&gt;CauseAbs&lt;/th&gt;
   &lt;th&gt;justifié&lt;th&gt;
   &lt;/tr&gt;";
    while($row = mysqli_fetch_array($result))  
    {  
          echo "&lt;tr&gt;";
   echo "&lt;td&gt;" . $row['NomEmp'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['PrénomEmp'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['DateD'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['DateF'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['CauseAbs'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['justifié'] . "&lt;/td&gt;";
   echo "&lt;/tr&gt;";  
    }  
    echo $output;  
  }  
  ?&gt;
  </code></pre>
  
  <p>can anyone help me to find the problem in this ? any help would be appreciated.
  Thanks.</p>