-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
136 lines (78 loc) · 2.53 KB
/
functions.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
123
124
125
126
127
128
129
130
131
132
133
134
<?php
require 'dbconfig.php';
// print("xxxxxxxxxxxxxxx");
// exit();
$table = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$table = isset($_POST["table"]) ? $_POST["table"] : "";
// $uname = isset($_POST["username"]) ? $_POST["username"] : "";
// $password = isset($_POST["password"]) ? $_POST["password"] : "";
// print($table);
// exit();
// print("email: ");
// print("password: ");
// print($email);
// print($password);
//echo "username and password: ",$uname,$pass;
}
$query = "select * from $table;";
// $query = "select title,description,user_id from posts where posts.id='$post_id';";
$conn = new mysqli($hn, $un, $pw, $db);
// print($query);
// exit();
if ($conn->connect_error) {
// print("At line 49");
echo json_encode(array("value" => 0, "message" => 'Connection error with database, please try again '));
// die($connection->connect_error);
}
$result = $conn->query($query);
if (!$result) {
// echo json_error('Email not found please enter valid email.');
echo json_encode(array("value" => 0, "message" =>'Empty result returned from functions'));
// die($connection->error);
} elseif (0 == ($result->num_rows)) {
echo json_encode(array("value" => 0, "message" =>'0 results returned from functions.'));
} else {
$num = $result->num_rows;
// $row = $result->fetch_array(MYSQLI_NUM);
// $row = $result->fetch_array(MYSQLI_ASSOC);
// print($row[0]);
// exit();
$id = '';
$value = '';
$index = 1;
// $oneLocation->id=0;
// $oneLocation->value='';
class location
{
public $id;
public $value;
}
$arrayOfLocations = array();
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$id = ($row['location_id']);
$value = ($row['value']);
$arrayItem = new location();
$arrayItem->value = $value;
$arrayItem->id = $id;
$arrayOfLocations[] = $arrayItem;
$index = $index + 1;
// print($location);
// array_push($location, $x);
// print($location);
// $location[$index]->id=$id;
// $location[$index]->value = $value;
//
// $index++;
}
$myJSON = json_encode($arrayOfLocations);
//var_dump($arrayOfLocations);
//exit();
//$myJSON = json_encode($location);
// echo json_encode($named_array);
echo json_encode(array("value" => 1, "message" =>$myJSON));
// print($myJSON);
}
$conn->close();
// $result->close();
return $result;