-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.php
51 lines (46 loc) · 1.6 KB
/
load.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
<?php
include 'includes/header.php';
include('database_connection.php');
$user_id = $_SESSION['id'];
$statement = $connect->prepare("
SELECT chat.id,
accounts.username,
chat.user_id,
chat.message,
chat.timestamp
FROM chat
JOIN accounts
ON chat.user_id = accounts.id
ORDER BY timestamp
");
$statement->execute();
$all_result = $statement->fetchAll();
$total_rows = $statement->rowCount();
if ($total_rows > 0) {
foreach ($all_result as $row) {
if ($row["user_id"] == $_SESSION['id']) {
$class = "message me";
$text = "text me";
}else{
$class = "message";
$text = "text";
}
echo '
<div class="' . $class . '">';
if ($row["user_id"] != $_SESSION['id']) {
echo '<img class="avatar-md" src="img/avatars/avatar-female-5.jpg" data-toggle="tooltip" data-placement="top" title="' . $row['username'] . '" alt="avatar">';
}
echo '
<div class="text-main">
<div class="' . $text . '">
<div class="">
<p>' . $row['username']. '</p>
<p>' . nl2br($row['message']) . '</p>
</div>
</div>
<span>' . date('g:i A', strtotime($row['timestamp'])) . '</span>
</div>
</div>
';
}
}