-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetReviews.php
49 lines (37 loc) · 1.11 KB
/
getReviews.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
<?php
//Get product data
$prodId = $_GET['prodId'];
$prodCat = $_GET['prodCat'];
//connect to server
include('./php/globals.php');
// Open new connection
$conn = open_db_conn();
if ($conn->connect_error)
{
echo '<script>alert("Connection failed!")</script>';
}
$getReviews = "SELECT users.firstname, users.lastname , reviews.rating , reviews.review
FROM reviews INNER JOIN users ON reviews.userid = users.userid AND
reviews.prodid = '$prodId' AND reviews.prodCat = '$prodCat'";
$result = mysqli_query($conn,$getReviews);
$count = mysqli_num_rows($result);
$products = array();
while($row = mysqli_fetch_array($result))
{
array_push($products, array(
"firstname"=>$row['firstname'],
"lastname"=>$row['lastname'],
"rating"=>$row['rating'],
"review"=>$row['review']
));
}
if($count > 0)
{
print(json_encode($products));
}
else
{
print("No products Found");
}
mysqli_close($conn);
?>