-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect_comment.php
More file actions
46 lines (43 loc) · 1.14 KB
/
select_comment.php
File metadata and controls
46 lines (43 loc) · 1.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
<?php
include("./connection.php");
$post_data = array(
"comment_data" => [],
);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id = $_POST['id'];
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$id = $_GET['id'];
}
$sql = "SELECT
`comment`.id,
`comment`.author,
`comment`.content,
`comment`.create_time,
`comment`.post_id,
`comment`.score,
`comment`.author_id,
`user`.image
FROM
`comment`
INNER JOIN post ON `comment`.post_id = $id AND `comment`.post_id = post.id
INNER JOIN `user` ON `comment`.author_id = `user`.id
-- ORDER BY `comment`.score DESC
";
$query = mysqli_query($connection, $sql);
if ($query != false) {
while ($items = mysqli_fetch_assoc($query)) {
// var_dump($items);
$data = array(
"id" => $items['id'],
"author" => $items['author'],
"content" => $items['content'],
"create_time" => $items['create_time'],
"score" => $items['score'],
"author_image" => $items['image']
);
array_push($post_data["comment_data"], $data);
}
}
echo json_encode($post_data);
// $comment_sql = "INSERT INTO comment VALUES(null,$user,$content)";