-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPost.php
More file actions
33 lines (24 loc) · 950 Bytes
/
getPost.php
File metadata and controls
33 lines (24 loc) · 950 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
<?php
include_once 'dbconfig.php';
$conn = mysqli_connect($dbconfig["host"], $dbconfig["user"], $dbconfig["password"], $dbconfig["name"]) or die("Errore: ".mysqli_connect_error());
$username = mysqli_real_escape_string($conn, $_GET["q"]);
$query = "SELECT * FROM posts WHERE username ='".$username."'";
$res = mysqli_query($conn, $query);
$jsonPosts = array();
while($row = mysqli_fetch_assoc($res)){
$jsonPosts[]=$row;
}
for ($i=0; $i < count($jsonPosts); $i++) {
$query_1 = "SELECT * FROM likes_for_posts WHERE user='$username' 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);
?>