-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.php
122 lines (120 loc) · 3.79 KB
/
sql.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
//设置页面内容是html编码格式是utf-8
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:POST,GET');
header('Access-Control-Allow-Credentials:true');
// header("Content-Type: text/plain;charset=utf-8");
header("Content-Type: application/json;charset=utf-8");
//header("Content-Type: text/xml;charset=utf-8");
//header("Content-Type: text/html;charset=utf-8");
//header("Content-Type: application/javascript;charset=utf-8");
$mysqli=new mysqli();//实例化mysqli
$mysqli->connect('localhost','root','root','zs');
if(mysqli_connect_error()){
exit('数据库连接错误,错误信息是.'.mysqli_connect_error());
}
$mysqli->set_charset("UTF8");//设置数据库编码
if (!isset($_POST['key'])) {
echo "请求失败";
return;
}else{
$key = $_POST['key'];
if ($key == 1) {
if (!isset($_POST["year"])||!isset($_POST["province"])||!isset($_POST["subject"])) {
echo "参数错误";
return;
}else{
$year = $_POST["year"];
$province = $_POST["province"];
$subject = $_POST["subject"];
}
$sqlzsjh="select `major`,`plan`,`nature`,`tuition` from `jhfs` where `year` like '{$year}' and `province` like '{$province}' and `subject` like '{$subject}'";//创建一句SQL语句
$zsjh=$mysqli->query($sqlzsjh);
$data1 = array();
if ($zsjh->num_rows > 0) {
while ($row = $zsjh->fetch_assoc()) {
array_push($data1, $row);
}
}else {
echo "没有数据";
}
$json1 = json_encode($data1);
$zsjh->free();
echo $json1;
}elseif ($key == 2) {
if (!isset($_POST["year"])||!isset($_POST["province"])||!isset($_POST["subject"])) {
echo "参数错误";
return;
}else{
$year = $_POST["year"];
$province = $_POST["province"];
$subject = $_POST["subject"];
}
if ($year == '0000') {
$sqllnfs="select `year`,`batch`,`minscore`,`controlline` from `gxfs` where `province` like '{$province}' and `subject` like '{$subject}'";
}else {
$sqllnfs="select `year`,`batch`,`minscore`,`controlline` from `gxfs` where `year` like '{$year}' and `province` like '{$province}' and `subject` like '{$subject}'";
}
$lnfs=$mysqli->query($sqllnfs);
$data2 = array();
if ($lnfs->num_rows > 0) {
while ($row = $lnfs->fetch_assoc()) {
array_push($data2, $row);
}
}else {
echo "没有数据";
}
$json2 = json_encode($data2);
$lnfs->free();
echo $json2;
}elseif ($key == 3) {
if (!isset($_POST["year"])||!isset($_POST["province"])||!isset($_POST["subject"])) {
echo "参数错误";
return;
}else{
$year = $_POST["year"];
$province = $_POST["province"];
$subject = $_POST["subject"];
}
$sqllnfs2="select `major`,`minscore`,`avgscore`,`enroll`,`remarks` from `jhfs` where `year` like '{$year}' and `province` like '{$province}' and `subject` like '{$subject}'";
$lnfs2=$mysqli->query($sqllnfs2);
$data3 = array();
if ($lnfs2->num_rows > 0) {
while ($row = $lnfs2->fetch_assoc()) {
if ($row['remarks'] == null) {
$row['remarks'] = "无";
}
array_push($data3, $row);
}
}else {
echo "没有数据";
}
$json3 = json_encode($data3);
$lnfs2->free();
echo $json3;
}elseif ($key == 4) {
if (!isset($_POST["year"])||!isset($_POST["province"])||!isset($_POST["subject"])) {
echo "参数错误";
return;
}else{
$year = $_POST["year"];
$province = $_POST["province"];
$subject = $_POST["subject"];
}
$sqllnfs3="select `major`,`minscore`,`avgscore`,`enroll` from `jhfs` where `year` like '{$year}' and `province` like '{$province}' and `subject` like '{$subject}'";
$lnfs3=$mysqli->query($sqllnfs3);
$data4 = array();
if ($lnfs3->num_rows > 0) {
while ($row = $lnfs3->fetch_assoc()) {
array_push($data4, $row);
}
}else {
echo "没有数据";
}
$json4 = json_encode($data4);
$lnfs3->free();
echo $json4;
}
}
$mysqli->close();//别忘了关闭你的"小资源";
?>