Repository navigation
Expand file tree
/
Copy pathdisplay_comments.php
More file actions
73 lines (59 loc) · 2.14 KB
/
Copy pathdisplay_comments.php
File metadata and controls
73 lines (59 loc) · 2.14 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// set or include db.php file
include 'db.php';
// init output
$output = '';
// do a select query with order by to sort the new comments on tbl_comment
$query = "SELECT * FROM tbl_comment WHERE parent_id = 0 ORDER BY id DESC";
$stmt = $db->prepare($query);
$stmt->execute();
$res = $stmt->get_result();
// looping the data
while ($row = $res->fetch_assoc()) {
// do join output
$output .= '
<div class="card border border-1 p-3 mb-2 me-1 bg-white text-dark">
<i class="bi bi-person-circle" style="font-size:30px;"> <span class="fst-normal fw-bold" style="font-size:19px;">' .$row["name"] . '</span></i>
<div class="card-body">
<p>' . $row["comment"] . '</p>
</div>
<div class="col-se-5 mt-5">
<i class="bi bi-clock"> ' . $row["comment_date"] . '</i>
<button type="button" class="btn btn-primary float-end reply" id="' . $row["id"] . '">Reply</button>
</div>
</div>
';
$output .= get_reply($db, $row["id"]);
}
// show the results
echo $output;
// function get_reply is used to reply to user comments
function get_reply($db, $parent_id = 0)
{
$output = '';
$query = "SELECT * FROM tbl_comment WHERE parent_id=?";
$stmt = $db->prepare($query);
$stmt->bind_param("s", $parent_id);
$stmt->execute();
$res = $stmt->get_result();
$count = $res->num_rows;
if ($count > 0) {
while ($row = $res->fetch_assoc()) {
$output .= '
<div class="card border border-1 p-3 mb-2 bg-white text-dark me-2" style="margin-left:30px;">
<i class="bi bi-person-circle" style="font-size:30px;"> <span class="fst-normal fw-bold" style="font-size:19px;">' .$row["name"] . '</span></i>
<div class="card-body">
<p>' . $row["comment"] . '</p>
</div>
<div class="col-se-5 mt-5">
<i class="bi bi-clock"> ' . $row["comment_date"] . '</i>
<button type="button" class="btn btn-primary float-end reply" id="' . $row["id"] . '">Reply</button>
</div>
</div>
';
$output .= get_reply($db, $row["id"]);
}
}
return $output;
}
?>