-
Notifications
You must be signed in to change notification settings - Fork 0
/
buddy_messages.php
71 lines (56 loc) · 2.34 KB
/
buddy_messages.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
<?php
include "db_conn.php";
if (isset($_POST['userid']) && isset($_POST['buddyid']) && isset($_POST['groupid'])) {
$userid = $_POST["userid"];
$buddyid = $_POST["buddyid"];
$groupid = $_POST["groupid"];
$i = 0;
$sql1 = "SELECT * FROM `messages` WHERE `groupid` = '$groupid' ORDER BY `id` ASC";
$result1 = mysqli_query($conn, $sql1);
if (mysqli_num_rows($result1) > 0) {
while ($row = mysqli_fetch_assoc($result1)) {
$id = $row["id"];
$senderid = $row["senderid"];
$receiverid = $row["receiverid"];
$message = $row["message"];
$timestamp = $row["timestamp"];
$sql2 = "SELECT * FROM `account` WHERE `userid` = '$buddyid'";
$result2 = mysqli_query($conn, $sql2);
if (mysqli_num_rows($result2) > 0) {
while ($row = mysqli_fetch_assoc($result2)) {
$buddy_username = $row["username"];
$buddy_profile = $row["profile"];
if ($senderid == $userid) {
echo '
<div id="my-msg-con">
<h3 id="my-message" title="'. $timestamp .'">'. $message .'</h2>
</div>';
$i = 0;
} else {
if ($i == 0) {
echo '
<div class="message-wrapper" id="sender-msg-con">
<img src="documents/profile/'. $buddy_profile .'" alt="profile-img" id="sender-profile">
<h3 id="sender-message" title="'. $timestamp .'">'. $message .'</h2>
</div>';
$i = 1;
} else {
echo '
<div class="message-wrapper" id="sender-msg-con">
<div id="space"></div>
<h3 id="sender-message" title="'. $timestamp .'">'. $message .'</h2>
</div>';
}
}
}
} else {
// echo "Failed";
}
}
} else {
// echo "Failed";
}
} else {
echo "Unknown";
}
?>