-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadProducts.php
More file actions
52 lines (35 loc) · 1.32 KB
/
Copy pathReadProducts.php
File metadata and controls
52 lines (35 loc) · 1.32 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
<?php
/**
* Created by PhpStorm.
* User: dronca
* Date: 11/9/18
* Time: 10:45 PM
*/
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Credentials: true");
header('Content-Type: application/json');
include_once 'lib/Coffee.php';
include_once 'lib/DBHelper.php';
$dbh = new DBHelper();
$query = "SELECT country, name, price, description, productCode, thumbnail, viewCount FROM `Coffee` ORDER BY country, name ASC";
$result = $dbh->query($query);
$products = array();
while ($row = mysqli_fetch_array($result)){
$curRet = array();
$curProd = Coffee::fromRow($row);
$curRet["name"] = $curProd->country." ".$curProd->name;
$curRet["price"] = $curProd->price;
$curRet["productCode"] = $curProd->productCode;
$curRet["averageRating"] = $curProd->avgRating;
$curRet["viewCount"] = $curProd->viewCount;
$curRet["thumbnail"] = "http://roncabeanz.com/Roncabeanz/$curProd->thumbnail";
$curRet["clickTo"] = "http://roncabeanz.com/Roncabeanz/ShowCoffee.php?productCode=$curProd->productCode";
$curRet["description"] = $curProd->description;
array_push($products, $curRet);
}
// set response code - 200 OK
http_response_code(200);
// make it json format
echo json_encode($products);