-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
35 lines (29 loc) · 881 Bytes
/
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
<?php
// Database configuration
$dbHost = "localhost";
$dbUsername = "root";
$dbPassword = "RFVbgt%6";
$dbName = "fed_contractor";
// Create database connection
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
// Check connection
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
echo("DB Connected");
// Get search term
$searchTerm = $_GET['term'];
// Fetch matched data from the database
$query = $db->query("SELECT * FROM skills WHERE skill LIKE '%".$searchTerm."%' AND status = 1 ORDER BY skill ASC");
// Generate array with skills data
$skillData = array();
if($query->num_rows > 0){
while($row = $query->fetch_assoc()){
$data['id'] = $row['id'];
$data['value'] = $row['skill'];
array_push($skillData, $data);
}
}
// Return results as json encoded array
echo json_encode($skillData);
?>