-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_all_users.php
executable file
·47 lines (34 loc) · 1.02 KB
/
get_all_users.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
<?php
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from users table
$result = mysql_query("SELECT *FROM users") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
$response["users"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$user = array();
$user["UserID"] = $row["UserID"];
$user["Forename"] = $row["Forename"];
$user["Surname"] = $row["Surname"];
// push single product into final response array
array_push($response["users"], $user);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No userss found";
// echo no users JSON
echo json_encode($response);
}
?>