1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| <?php
$host = "localhost";
$user = "root";
$pass = "Mm101010";
$bdd = "smartphone";
$port = '3306';
try{
$cnx = new PDO ('mysql:host='.$host.';dbname='.$bdd, $user, $pass);
}
catch (PDPExeption $e)
{
echo $e->getMessage();
}
if(isset($_GET['motclef'])) {
$motclef = $_GET['motclef'];
$q = array('motclef' =>$motclef. '%');
$sql ='SELECT Nom,Operateur FROM select_nom_prenom_user WHERE Nom like :motclef or Operateur like :motclef';
$req = $cnx->prepare($sql);
$req->execute($q);
$count = $req->rowCount($sql);
if($count == 1){
while ($result =$req->fetch(PDO::FETCH_OBJ)){
echo "Nom :".$result->Nom."<br/>Operateur :".$result->Operateur;
}
}else{
echo "Aucun résultat pour :".$motclef;
}
}
?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/css"; charset="utf-8"/>
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#recherche").keyup(function() {
var recherche = $(this).val();
var data = 'motclef=' + recherche;
if (recherche.lenth>3) {
$.ajax({
type : "GET",
url : "result.php",
data : data,
success: function(server_response){
$("#resultat").html(server_response).show();
}
});
}
});
});
</script>
</head>
<body>
<div class="wrap">
<div class="search">
<input type="text" name="recherche" class="text" id="recherche">
</div>
<div class="resultat" id="#resultat"></div>
</div>
</body>
</html> |