-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_comment.php
More file actions
52 lines (45 loc) · 1.8 KB
/
Copy pathfetch_comment.php
File metadata and controls
52 lines (45 loc) · 1.8 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
<?php
include_once "conn.php";
$output = '';
$sql = "SELECT * FROM tbl_comment WHERE parent_id = 0 ORDER BY id DESC";
$result = $obj->run->query($sql);
while($row = $result->fetch_assoc()){
$output .= '
<div class="card" style="margin-bottom: 20px;">
<div class="card-body">
<h5 class="card-title">'.$row['username'].'</h5>
<p class="card-text">'.$row['comment'].'</p>
<a href="#" class="reply card-link btn btn-info btn-sm" id="'.$row['id'].'">Reply</a>
</div>
</div>
';
$output .= fetch_reply($obj, $row['id']);
}
echo $output;
function fetch_reply($obj, $parent_id = 0, $marginleft = 0){
$sql = "SELECT * FROM tbl_comment WHERE parent_id = '".$parent_id."' ";
$result = $obj->run->query($sql);
$count = $result->num_rows;
$output = '';
if($parent_id == 0){
$marginleft = 0;
} else{
$marginleft = $marginleft + 30;
}
if($count > 0){
while($row = $result->fetch_assoc()){
$output .= '
<div class="card" style="margin-bottom: 20px; margin-left: '.$marginleft.'px;">
<div class="card-body">
<h5 class="card-title">'.$row['username'].'</h5>
<p class="card-text">'.$row['comment'].'</p>
<a href="#" class="reply card-link btn btn-info btn-sm" id="'.$row['id'].'">Reply</a>
</div>
</div>
';
$output .= fetch_reply($obj, $row['id'], $marginleft);
}
}
return $output;
}
?>