/
api_list_daily_englich.php
51 lines (44 loc) · 1.15 KB
/
api_list_daily_englich.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
<?php
require_once 'conn.php';
header('Content-type:application/json;charset=utf-8'); //要輸出 json 記得要加這行 header,瀏覽器才會知道他是 json 格式的資料
header('Access-Control-Allow-Origin: *');
function getJson($message)
{
$json = array(
"ok" => false,
"message" => $message,
);
$response = json_encode($json); //變成 json 的格式
echo $response;
die();
}
// get id
$sql = "SELECT * FROM record_daily_id WHERE username = 'gushanvic'";
$result = $conn->query($sql);
if (!$result) {
die($conn->error);
}
$row = $result->fetch_assoc();
$id = $row['id'];
//get daily english sentence
$sql = "SELECT * FROM daily_english WHERE id = ? AND is_deleted IS NULL";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $id);
$result = $stmt->execute();
$result = $stmt->get_result();
$dailyEnglish = array();
$row = $result->fetch_assoc();
array_push($dailyEnglish, array(
"id" => $row["id"],
"zh" => $row["zh"],
"en" => $row["en"],
));
if (!$result) {
getJson($conn->error);
}
$json = array(
"ok" => true,
"dailyEnglish" => $dailyEnglish,
);
$response = json_encode($json);
echo $response;