-
Notifications
You must be signed in to change notification settings - Fork 1
/
posts.php
72 lines (51 loc) · 2.93 KB
/
posts.php
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
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
include 'db-connect.php';
$code = $_GET["code"];
$aid = $_GET['aid'];
$username = $_SESSION["username"];
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FOR UPDATING DATABASE
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if($code == 1){ //CODE FOR LIKE
$likes = $_GET['likes'];
$sql = "UPDATE apartment SET likes='".$likes."' WHERE aid=".$aid;
}else if ($code == 2){ //CODE FOR DISLIKE
$dislikes = $_GET['dislikes'];
$sql = "UPDATE apartment SET dislike='".$dislikes."' WHERE aid=".$aid;
}else if($code == 0){
$report = $_GET['reports'];
$sql = "UPDATE apartment SET report='".$report."' Where aid =".$aid;
}
//Executes Statement
$conn->query($sql);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FOR UPDATING COUNTS UI
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$sql = "SELECT aid,likes,dislike,report from apartment where aid = ".$aid;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$aid = $row["aid"];
$sql_sl = 'SELECT app_status from apply_apt where TID=0 and username="'.$username.'" and aid = '. $aid;
$result_sl= $conn->query($sql_sl);
if ($result_sl->num_rows > 0) {
echo '
<button type = "button"> Applied </button>
<button onclick = "clickFunction(1,'.$row["aid"].','.$row["likes"].')" value = "'.$row["likes"].'" type = "button"> Like ('.$row["likes"].')</button>
<button onclick = "clickFunction(2,'.$row["aid"].','.$row["dislike"].')" value = "'.$row["dislike"].'" type = "button"> Dislike ('.$row["dislike"].')</button>
<button onclick = "clickFunction(0,'.$row["aid"].','.$row["report"].')" value = "'.$row["report"].'" type = "button"> Report ('.$row["report"].')</button>';
}else{
echo '
<button onclick = "applyFunction('.$row["aid"].')" type = "button"> Apply </button>
<button onclick = "clickFunction(1,'.$row["aid"].','.$row["likes"].')" value = "'.$row["likes"].'" type = "button"> Like ('.$row["likes"].')</button>
<button onclick = "clickFunction(2,'.$row["aid"].','.$row["dislike"].')" value = "'.$row["dislike"].'" type = "button"> Dislike ('.$row["dislike"].')</button>
<button onclick = "clickFunction(0,'.$row["aid"].','.$row["report"].')" value = "'.$row["report"].'" type = "button"> Report ('.$row["report"].')</button>';
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$conn->close();
?>