Repository navigation
Expand file tree
/
Copy pathsearch.json.bak.php
More file actions
152 lines (130 loc) · 3.76 KB
/
Copy pathsearch.json.bak.php
File metadata and controls
152 lines (130 loc) · 3.76 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
require 'functions.php';
header('Content-type:application/json');
$jsonData = file_get_contents("php://input");
$obj = json_decode($jsonData);
$DBlink = openMysql();
// query shops
$query = "";
// keyword
if ($obj->{'keyword'} != "") {
if ($query == "") {
$query = $query . " where";
} else {
$query = $query . " and";
}
$query = $query . sprintf(" ((shopname like binary '%%%s%%') or (score_all like binary '%%%s%%') or (abstract like binary '%%%s%%') or (qualification like binary '%%%s%%'))", $obj->{'keyword'}, $obj->{'keyword'}, $obj->{'keyword'}, $obj->{'keyword'});
}
// district
if ($obj->{'distinct'} != "") {
if ($query == "") {
$query = $query . " where";
} else {
$query = $query . " and";
}
$query = $query . sprintf(" district=\"%s\"", $obj->{'distinct'});
}
// score
if ($obj->{'score'} != "") {
if ($query == "") {
$query = $query . " where";
} else {
$query = $query . " and";
}
$query = $query . sprintf(" score_all=\"%s\"", $obj->{'score'});
}
// qualification
if ($obj->{'qualify'} != "") {
if ($query == "") {
$query = $query . " where";
} else {
$query = $query . " and";
}
if ($obj->{'qualify'} == "none") {
$query = $query . " qualification is null";
} else {
switch ($obj->{'qualify'}) {
case "sjsg1":
$qualify = "设计施工一级";
break;
case "sjsg2":
$qualify = "设计施工二级";
break;
case "sjsg3":
$qualify = "设计施工三级";
break;
case "sj1":
$qualify = "设计一级";
break;
case "pro":
$qualify = "专业级";
break;
case "pro_intern":
$qualify = "专业级(暂定)";
break;
default:
$qualify = $obj->{'qualify'};
}
$query = $query . sprintf(" qualification like binary '%%%s%%'", $qualify);
}
}
// average
if ($obj->{'average'} != "") {
if ($query == "") {
$query = $query . " where";
} else {
$query = $query . " and";
}
switch ($obj->{'average'}) {
case '3to5':
$cond = ' dp_price >= 30000 and dp_price <= 50000';
break;
case '5to7':
$cond = ' dp_price >= 50000 and dp_price <= 70000';
break;
case '7to10':
$cond = ' dp_price >= 70000 and dp_price <= 100000';
break;
case '10to15':
$cond = ' dp_price >= 100000 and dp_price <= 150000';
break;
case '15up':
$cond = ' dp_price >= 150000';
break;
default:
$cond = $obj->{'average'};
}
$query = $query . $cond;
}
// count
$countQuery = "select COUNT(*) from shop" . $query .";";
$result = mysql_query($countQuery, $DBlink) or die("Query failed:".mysql_error());
list($count) = mysql_fetch_row($result);
$count = intval($count, 10);
$limitStart = $obj->{'page'} * $obj->{'limit'};
if ($limitStart > $count) {
$page = (int)($count / $obj->{'limit'});
$limitStart = $page * $obj->{'limit'};
} else {
$page = $obj->{'page'};
}
// order by
$orderClause = sprintf(" order by image<>\"\" DESC, %s DESC", $obj->{'sortType'});
// limit clause
$limitClause = sprintf(" limit %d, %d", $limitStart, $obj->{'limit'});
// shops
$query = "select * from shop" . $query . $orderClause . $limitClause;
$result = mysql_query($query, $DBlink) or die("Query failed:".mysql_error());
$arr = Array();
$num = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$arr[$num] = $row;
$num++;
}
// close connection
mysql_close($DBlink);
$retObj->count = $count;
$retObj->arr = $arr;
$retObj->page = $page;
echo json_encode($retObj);
?>