Guest User

Untitled

a guest
Jan 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. $bdd = new PDO('mysql:host='.$sql_serveur.';dbname='.$sql_bdd.'', $sql_user, $sql_mdp);
  2.  
  3. if(isset($_GET['user'])){
  4. $user = (String) trim($_GET['user']);
  5.  
  6. $req = $DB->query("SELECT *
  7. FROM utilisateur
  8. WHERE nom LIKE ?
  9. LIMIT 10",
  10. array("$user%"));
  11.  
  12. $req = $req->fetchALL();
  13.  
  14. foreach($req as $r){
  15. ?>
  16. <div style="margin-top: 20px 0; border-bottom: 2px solid #ccc">
  17. <?= $r['nom'] . " " . $r['prenom'] ?>
  18. </div>
  19. <?php
  20. } }
  21.  
  22. <div class="form-group">
  23. <input class="form-control" type="text" id="search-user" value="" placeholder="Rechercher un ou plusieurs utilisateurs"/>
  24. </div>
  25. <div style="margin-top: 20px">
  26. <div id="result-search"></div> <!-- C'est ici que nous aurons nos résultats de notre recherche -->
  27. </div>
  28.  
  29. $(document).ready(function(){
  30. $('#search-user').keyup(function(){
  31. $('#result-search').html('');
  32.  
  33. var utilisateur = $(this).val();
  34.  
  35. if(utilisateur != ""){
  36. $.ajax({
  37. type: 'GET',
  38. url: 'php/user_research.php',
  39. data: 'user=' + encodeURIComponent(utilisateur),
  40. success: function(data){
  41. if(data != ""){
  42. $('#result-search').append(data);
  43. }else{
  44. document.getElementById('result-search').innerHTML = "<div style='font-size: 20px; text-align: center; margin-top: 10px'>Aucun utilisateur</div>"
  45. }
  46. }
  47. });
  48. }
  49. });
  50. });
Add Comment
Please, Sign In to add comment