-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
98 lines (73 loc) · 2.21 KB
/
Copy pathapi.php
File metadata and controls
98 lines (73 loc) · 2.21 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
include "config/conn.php";
include "lib/Database.php";
include "helpers/Format.php";
class API{
private $db;
private $format;
private $address;
function __construct(){
$this->db = new Database();
$this->format = new Format();
$this->address = "http://localhost/math-contest/";
}
public function Select($id){
$id = $this->format->Stext($id);
$users = array();
$data = $this->db->select("SELECT * FROM register WHERE id=$id");
if($data){
while ($output = $data->fetch_assoc()) {
$users = array(
'id' => $output['id'],
'user_name' => $output['user_name'],
'user_email' => $output['user_email']
);
}
return json_encode($users);
}else{
echo "perameter wrong";
}
} // end function
public function fetchProblem($id){
$id = $this->format->Stext($id);
$users = array();
$data = $this->db->select("SELECT * FROM post WHERE id=$id");
if($data){
while ($output = $data->fetch_assoc()) {
$users = array(
'id' => $output['id'],
'post_title' => $output['post_title'],
'post_content' => $output['post_content'],
'post_image' => $this->address.$output['post_image'],
'post_author' => $output['post_author']
);
}
return json_encode($users);
}else{
echo "perameter wrong";
}
} // end function
}
if(isset($_REQUEST['id']) != null){
if($_REQUEST['id'] != null){
$id = $_REQUEST['id'];
$API = new API();
header('Content-Type: application/json');
echo $API->Select($id);
}
else{
echo "something went wrong";
}
}
if(isset($_REQUEST['fetchmath']) != null){
if($_REQUEST['fetchmath'] != null){
$id = $_REQUEST['fetchmath'];
$API = new API();
header('Content-Type: application/json');
echo $API->fetchProblem($id);
}
else{
echo "something went wrong";
}
}
?>