-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearching_using_ajax.php
66 lines (61 loc) · 1.3 KB
/
searching_using_ajax.php
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
<html>
<head>
<title>Search</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
#show_up{
border: 1px solid #ddd;
/* display: none; */
}
#show_up a{
border-bottom: 1px solid #ddd;
display: block;
text-decoration: none;
padding: 5px;
}
</style>
</head>
<body>
<script>
$(document).ready(function(e){
$("#search").keyup(function(){
$("#show_up").show();
var text = $(this).val();
$.ajax({
type: 'GET',
url: 'search.php',
data: 'txt=' + text,
success: function(data){
$("#show_up").html(data);
}
});
})
});
</script>
<input type="text" name="names" id="search" />
<div id="show_up">
<?php
$db_host='127.0.0.1';
$db_user='root';
$db_pass='';
$db_name='english';
$conn=mysqli_connect($db_host,$db_user,$db_pass,$db_name);
if(!$conn )
{
die('Failed to connect mysql database'.mysqli_connect_error());
}
// echo "YOYO";
$sql='SELECT * from words';
$query = mysqli_query($conn,$sql);
if(!$query)
{
die('error found'.mysqli_error($conn));
}
while($row=mysqli_fetch_array($query))
{
echo '<p>'.$row['word'].'</p>';
}
?>
</div>
</body>
</html>