-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnewmsg.php
55 lines (45 loc) · 1.57 KB
/
newmsg.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
<?php
session_start();
include_once 'include/check_user.php';
include_once 'db/db_conn_pdo.php';
$r_id = $_POST["rid"];
$sql = "select username, is_active, prof_img from users where user_id= ?";
$result = $conn->prepare($sql);
$result->execute([$r_id]);
$row = $result->fetch(PDO::FETCH_OBJ);
$sql_user = "select user_id, is_active, prof_img from users where user_id= ?";
$result_user = $conn->prepare($sql_user);
$result_user->execute([$_SESSION["usr_id"]]);
$row_user = $result_user->fetch(PDO::FETCH_OBJ);
$sql = "select * from messages where
(CASE
when sender_id= ? and sender_flag=0x01
then receiver_id= ?
when sender_id= ? and receiver_flag=0x01
then receiver_id= ?
END) order by time ASC";
$stmt = $conn->prepare($sql);
$stmt->execute([$_SESSION["usr_id"], $r_id, $r_id, $_SESSION["usr_id"]]);
$upsql = "update messages set sender_flag = 0x00 where sender_id= ? and receiver_id= ?";
$stmt_update = $conn->prepare($upsql);
$stmt_update->execute([$_SESSION["usr_id"], $r_id]);
$upslt = "update messages set receiver_flag = 0x00 where sender_id= ? and receiver_id= ?";
$stmt_update = $conn->prepare($upslt);
$stmt_update->execute([$r_id, $_SESSION["usr_id"]]);
if ( $stmt->rowCount() ) {
$data=array();
array_push($data,$row);
array_push($data,$row_user);
while ( $row = $stmt->fetch(PDO::FETCH_OBJ) ) {
array_push( $data,$row );
}
echo json_encode($data);
exit();
}
else {
$myArr = array("");
$myJSON = json_encode($myArr);
echo $myJSON;
exit();
}
?>