forked from sneha2245/online-chatting-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchbarchat.php
62 lines (50 loc) · 2.09 KB
/
searchbarchat.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
<?php
if(isset($_REQUEST["chatSerach"])){
$servername="localhost";
$username="root";
$password="";
$dbName="chatting-system";
$port="3308";
$conn = mysqli_connect($servername, $username, $password, $dbName, $port);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// var_dump($_POST);
$sen=$_POST["sender"];
$rev=$_POST["receiver"];
// $sql = "select * from users left join chat_content on chat_content.senderId = users.id where ((chat_content.senderId = ".$sen." and chat_content.receiverId = ".$rev.") or (chat_content.senderId = ".$rev." and chat_content.receiverId = ".$sen.")) and chat_content.content like ? order by(chat_content.id)";
$sql = "select * from chat_content where ((chat_content.senderId = ".$sen." and chat_content.receiverId = ".$rev.") or (chat_content.senderId = ".$rev." and chat_content.receiverId = ".$sen."))and content like ? order by(chat_content.id)";
if($stmt = mysqli_prepare($conn, $sql)){
mysqli_stmt_bind_param($stmt,"s",$param_term);
$param_term = $_REQUEST["chatSerach"] . '%';
if(mysqli_stmt_execute($stmt)){
$result = mysqli_stmt_get_result($stmt);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$datePicker=$row["current_time"];
$date = date('d/m/yy g:i a',strtotime($datePicker));
echo '<div class="col-md-12 col-sm-12">'.
'<div class="row">'.
'<div class="col-md-12 col-sm-12">'.
'<div class="serach_chat_time">'.
$date.
'</div>'.
'<div class="serach_chat">'.
$row["content"].
'</div>'.
'<div style="margin-top: 10px;" class="border-avaliable">'.'</div>'.
'</div>'.
'</div>'.
'</div>';
}
}else{
echo '<h5 style="margin-top: 10px;margin-left: 10px;">No matches found</h5>';
}
}else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
?>