-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.php
68 lines (56 loc) · 1.74 KB
/
translate.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
67
68
<?php
// connection to database
$conn = mysqli_connect('localhost', 'root', '');
$ps = 0;
if (!$conn) {
$ps++;
}
$pilihDB = mysqli_select_db($conn, 'userform');
$kata = $_GET['kata'];
$bahasa = $_GET['bahasa'];
if ($ps == 0) {
if ($bahasa == "indonesia") {
$cari = mysqli_query($conn, "SELECT * FROM translate WHERE indonesia='$kata'");
} else if ($bahasa == "sumbawa") {
$cari = mysqli_query($conn, "SELECT * FROM translate WHERE sumbawa='$kata'");
}
$jum = mysqli_num_rows($cari);
if ($jum == 0) {
// print("kata tidak tersedia");
echo json_encode([
"status" => false,
"kata" => "kata tidak tersedia",
"ket" => ""
]);
} else {
$data = mysqli_fetch_array($cari);
if ($bahasa == "indonesia") {
echo json_encode([
"status" => true,
"kata" => $data['sumbawa'],
"ket" => $data['keterangan'],
]);
// print($data['sumbawa']);
} else if ($bahasa == "sumbawa") {
//print($data['indonesia']);
echo json_encode([
"status" => true,
"kata" => $data['indonesia'],
"ket" => $data['keterangan'],
]);
}
}
}
if(isset($_GET['query'])){
$keyword = $_GET['query'];
$query = mysqli_query($conn,"SELECT * FROM translate WHERE indonesia LIKE '%".$keyword."%' ORDER BY id LIMIT 10");
while ($data = mysqli_fetch_array($query)) {
$output['suggestions'][] = [
'value' => $data['indonesia'],
'indonesia' => $data['indonesia']
];
}
if (! empty($output)) {
echo json_encode($output);
}
}