-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathkode.php
41 lines (34 loc) · 1.15 KB
/
kode.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
<?php
// Cegah direct akses ajax.
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
// Set header type konten.
header("Content-Type: application/json; charset=UTF-8");
require_once "include/config.php";
require_once "include/functions.php";
// Koneksi ke database.
$conn = mysqli_connect($host, $username, $password, $database);
// Deklarasi variable keyword kode.
$kode = $_GET["query"];
// Query ke database.
$query = mysqli_query($conn, "SELECT * FROM tbl_klasifikasi
WHERE kode LIKE '%$kode%'
OR nama LIKE '%$kode%'
OR uraian LIKE '%$kode%'");
if (mysqli_num_rows($query) > 0){
// Format bentuk data untuk autocomplete.
while ($data = mysqli_fetch_assoc($query)) {
$output['suggestions'][] = [
'value' => $data['kode'] . " " . $data['nama'],
'kode' => $data['kode']
];
}
} else {
$output['suggestions'][] = [
'value' => '',
'kode' => ''
];
}
// Encode ke json.
echo json_encode($output);
}