-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_prices.php
36 lines (33 loc) · 920 Bytes
/
get_prices.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
<?php
$msg = "";
$success=false;
require_once 'db_functions.php';
$conn = connect_db();
if(gettype($conn) == 'string') {
$msg = "DB Error: ".$conn;
} else {
// $query = "SELECT `id`,'name', `price` from `stocks`";
$query = "SELECT id, name, price, remaining from stocks;";
if(!$result = $conn->query($query)) {
$msg = "<p>DB Error: " . $conn->error . "</p>";
} else {
$success = true;
while($row = $result->fetch_array()) {
$id = $row[0];
// $prices[$id] = $row[2];
// $name[$id] = $row[1];
// $id = $row[0];
// $data[name] = $row[1];
// $prices[price] = $row[2];
$data[$id][0] = $row[1];
$data[$id][1] = $row[2];
$data[$id][2] = $row[3];
}
}
close_db($conn);
}
if($success)
echo json_encode(Array('success'=>1, 'data'=>$data),JSON_PRETTY_PRINT,JSON_UNESCAPED_SLASHES);
else
echo json_encode(Array('success'=>0,'message'=>$msg),JSON_PRETTY_PRINT,JSON_UNESCAPED_SLASHES);
?>