-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-review.inc.php
47 lines (38 loc) · 1.44 KB
/
fetch-review.inc.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
include_once './functions.php';
include_once './src/inc/session.php';
if (isset($_POST['action'])) {
$limit = 6;
$output = "";
$pagintion = "";
if (isset($_POST['pid']) && !empty($_POST['pid'])) {
$pdo = pdo_connect_mysql();
$pid = $_POST['pid'];
if (isset($_POST['page']) >= 1) {
$start = (($_POST['page'])-1) * $limit;
$page = $_POST['page'];
} else {
$start = 0;
}
$query = "SELECT * FROM review WHERE product_id = $pid ORDER BY id DESC LIMIT $start, $limit";
$stmt = $pdo->query($query);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$totalRow = $stmt->rowCount();
if($totalRow > 0) {
foreach ($result as $review) {
$aid = $review['account_id'];
$user = user($aid);
$output .= reviewThemplate($review, $user);
}
$sql = "SELECT * FROM review WHERE product_id = $pid";
$stmt = $pdo->query($sql);
$totalReviews = $stmt->rowCount();
$totalPages = ceil($totalReviews/$limit);
$pagination = ajaxPagination($page, $totalPages);
}
}
$response = ['output'=>$output, 'pagination'=>$pagination];
echo json_encode($response);
exit();
}
?>