-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsearch.php
46 lines (32 loc) · 1.01 KB
/
search.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
<?php
//create database connection
$server = "localhost";
$username = "root";
$password = "";
$dbname = "dbphpsearch";
$conn = mysqli_connect($server, $username, $password, $dbname);
if($_SERVER['REQUEST_METHOD']=='POST'){
if (isset($_POST['token'])) {
$search = mysqli_real_escape_string($conn, $_POST['token']);
//search related word from the database
$sql = "SELECT * FROM article WHERE a_title LIKE '%$search%' OR a_text LIKE '%search%' OR a_author LIKE '%search%' OR a_date LIKE '%search%'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
echo "There are"." ". $queryResult ." "."results!";
if ($queryResult > 0) {
while ($row = mysqli_fetch_assoc($result)) {
# code..
$row['a_title']
$row['a_text']
$row['a_date']
$row['a_author']
);
}
echo json_encode($cat_arr);
}else {
echo "There are no result matching your search!";
}
}
}
?>
</div>