-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchmessage.php
101 lines (92 loc) · 4.39 KB
/
fetchmessage.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<html>
<head>
<meta charset="UTF-8"/>
<title>Chat Me</title>
<meta name="keyword" content="profile" />
<meta http-equiv="X-UA-Compatible" content ="IE=edge">
<meta name = "viewport" content="width=device-width,initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jsfile.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.0.0/animate.min.css"/>
<link rel="stylesheet" src = "https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
<title>Chat Me</title>
</head>
<body class = "bg-light">
<?php
session_start();
$receiver = $_SESSION["friendUsername"];
if(isset($_SESSION['name']))
{
$sender = $_SESSION['name'];
}
else
{
header('location:index.php');
}
include ("object.php");
$callingObjectClass = new Database_object_oriented_index();
$conn = $callingObjectClass->connect_to_database_function();
if ($conn)
{
$sql = " SELECT * FROM `messages`
WHERE `sender` = '$sender'
AND `receiver` = '$receiver'
OR `sender` = '$receiver'
AND `receiver` = '$sender' ";
$result = $conn->query($sql);
if($result->num_rows > 0 )
{
//output data of each row
while($row = $result->fetch_assoc())
{
$message = $row["message"];
$image = $row['image'];
// if($image != ''){
// echo " <img alt = 'icon' src = '$image' style = 'height:200px; width:150px;margin-left:5px;margin:5px 5px 5px 5px;'/>";
// }
$getSenderDifferenceMessageColor = $row['sender'];
if($sender == $getSenderDifferenceMessageColor)
{
if($message !== ''){
echo " <p style ='margin-bottom:4px;background-color:
lightblue;padding:5px 15px 10px 10px ;border-radius:10px;
width:fit-content;margin-left:auto;'> $message </p> ";
}
if($image != ''){
echo " <p style ='margin-bottom:4px;background-color:
lightblue;padding:5px 15px 10px 10px ;border-radius:10px;
width:fit-content;margin-left:auto;'>
<img alt = 'icon' src = '$image' style = 'height:200px; width:150px;'/>
</p> ";
}
}
elseif ($getSenderDifferenceMessageColor !== $sender)
{
if($message){
echo " <p style ='margin-bottom:4px;background-color:
lightgreen;padding:3px 5px 5px 5px ;border-radius:
10px;width:fit-content;margin-left:5px;'> $message</p> ";
}
if($image != ''){
echo " <p style ='margin-bottom:4px;background-color:
lightgreen;padding:3px 5px 5px 5px ;border-radius:
10px;width:fit-content;margin-left:5px;'>
<img alt = 'icon' src = '$image' style = 'height:200px; width:150px;'/>
</p> ";
}
}
}
}
else
{
echo " <p>Your message would be displayed here</p>";
}
}
else
{
echo "Unable to connect to database";
}
?>