-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinquery.php
More file actions
106 lines (83 loc) · 2.29 KB
/
inquery.php
File metadata and controls
106 lines (83 loc) · 2.29 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
<?php
error_reporting(E_ALL);
function die_with_error($error) {
$ret = array(
"status" => "Failed",
"error" => $error
);
die(json_encode($ret));
}
if (!isset($_GET["bound"]) || !isset( $_GET['buyer']))
die_with_error("invalid parameters");
$bound = $_GET["bound"];
$buyer = $_GET['buyer'];
switch ($bound) {
case '0':
$lower_bound = 0;
$upper_bound = 50;
break;
case '1':
$lower_bound = 50;
$upper_bound = 100;
break;
case '2':
$lower_bound = 100;
$upper_bound = 200;
break;
case '3':
$lower_bound = 200;
$upper_bound = 500;
break;
case '4':
$lower_bound = 500;
$upper_bound = 1000;
break;
case '5':
$lower_bound = 1000;
$upper_bound = 10000;
break;
case '6':
$lower_bound = 10000;
break;
default:
break;
}
$hostname = 'localhost';
$username = 'jeremy';
$password = 'bbcc';
$dbname = 'SE';
mysql_connect($hostname, $username, $password) or die_with_error(mysql_error());
mysql_select_db($dbname) or die_with_error(mysql_error());
mysql_set_charset('utf8');
if ($upper_bound) {
$query = "select * from ordered where buyer_id like '%" . $buyer ."%' and final_price >= " . $lower_bound . " and final_price <=" . $upper_bound . " ;";
} else {
$query = "select * from ordered where buyer_id like '%" . $buyer ."%' and final_price >= " . $lower_bound . " ;";
}
$result = mysql_query($query);
if (! $result)
die_with_error(mysql_error());
$result_array = array();
while ($row = mysql_fetch_assoc($result)) {
array_push($result_array,
array(
"order_id" => $row['order_id'],
"order_date" => $row['order_date'],
"order_type" => $row['order_type'],
"goods_id" => $row['goods_id'],
"status" => $row['status'],
"single_price" => $row['single_price'],
"final_price" => $row['final_price'],
"discount" => $row['discount'],
"amount" => $row['amount'],
'buyer_id' => $row['buyer_id'],
"address" => $row['address'],
"seller_id" => $row['seller_id']
));
}
$ret = array(
"status" => "OK",
"data" => $result_array
);
die(json_encode($ret));
?>