-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexplorerGetPosts.php
More file actions
38 lines (24 loc) · 833 Bytes
/
explorerGetPosts.php
File metadata and controls
38 lines (24 loc) · 833 Bytes
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
<?php
include_once 'dbconfig.php';
$conn = mysqli_connect($dbconfig["host"], $dbconfig["user"], $dbconfig["password"], $dbconfig["name"]) or die("Errore: ".mysqli_connect_error());
$query = "SELECT * FROM posts LIMIT 20";
$user = mysqli_real_escape_string($conn, $_GET["q"]);
$jsonPosts = array();
$res = mysqli_query($conn, $query);
while($row = mysqli_fetch_assoc($res)) {
$jsonPosts[]=$row;
}
for ($i=0; $i < count($jsonPosts); $i++) {
$query_1 = "SELECT * FROM likes_for_posts WHERE user='$user' AND post_id=".$jsonPosts[$i]["id"]."";
$res1 = mysqli_query($conn, $query_1);
$row = mysqli_fetch_assoc($res1);
if($row){
$jsonPosts[$i]["ok"] = true;
} else {
$jsonPosts[$i]["ok"] = false;
}
}
echo json_encode($jsonPosts);
mysqli_free_result($res);
mysqli_close($conn);
?>