Arrange chat messages based on sending time












0















I want to show chat messages between two users e.g user1 and admin(i.e currently i am) .Here is my db structure :



enter image description here



What i have tried so far:



I have a message box where messages appear, on clicking a message a username(i.e currently user1) is sent to the php for fetching chat with that user.After the chat is fetched, a chatbox is shown with the chat.



        $user        = $_POST['user'];
$db_messages = $db_readAll("messages","sender,recipient,sending_time,read_time,recipient_status","WHERE (sender='admin' OR sender=$user) AND (recipient='admin' OR recipient=$user)","ORDER BY sending_time DESC");
$uchatMsgs = '';

foreach($db_messages as $key => $message) {
$sender=$recipient='';
if($message['sender']== $_SESSION['session']){
$name = $message['recipient'];
$sender .= '<li class="m0 p0"><div class="text-center"><small>'.$ToReadableTime('@'.$message['sending_time']).'</small></div><div class="list-group-item b0 m0 mb5" style="padding:10px 10px 0 10px !important;"><div class="chatContent themed-background b-rad-30 p10 text-light">sender</div></div></li>';
}
if($message['recipient']== $_SESSION['session']){
$name = $message['sender'];
$recipient .= '<li class="m0 p0"><div class="text-center"><small>'.$ToReadableTime('@'.$message['sending_time']).'</small></div><div class="list-group-item b0 m0" style="padding:10px 10px 0 10px !important;"><div class="online-users pull-left mr5"><img src="../uploads/userprofile/default/avatar.jpg" onerror="this.onerror=null;imgDefault(this);" alt="avatar" class="online-users-img"><span title="online"></span></div><div class="chatContent bg-lightgrey b-rad-30 p10">receiver</div></div></li>';
}
$uchatMsgs = $recipient.$sender;
}
echo json_encode(['uchatName'=>$name,'uchatMsgs' => $uchatMsgs]);


HTML:



<div class="widget shadow chatui chatui-window remove-radius-bottom chatui-window-close display-none">
<div class="widget-content widget-content-mini themed-background">
<a href="javascript:void(0)" class="chatui-action-open text-dark-op pull-right"><i class="fa fa-window-restore"></i></a>
<a href="javascript:void(0)" class="chatui-action-close text-dark-op pull-right"><i class="fa fa-window-minimize" style="vertical-align:top;"></i></a>
<a href="javascript:void(0)" class="text-dark-op pull-right"><i class="fa fa-cog"></i></a>
<a href="../profiles.php" class="text-light"><strong id="uchatName"></strong></a>
</div>
<div class="widget-content widget-content-mini chatui-talk p0">
<ul id="uchatMsgs"> </ul>
</div>
<div class="widget-content widget-content-full chatui-form remove-radius-bottom">
<form action="page_app_social.html" method="post" class="m0">
<input type="text" id="chat-message" name="chat-message" class="form-control" placeholder="Type a message and hit enter..">
</form>
</div>
</div>


Jquery:



function vchat_MSGS(user){
$.ajax({
type: 'POST',
url: '../core/ajaxpdo.class.php',
dataType: 'json',
data: {page:'page_header',action:'vchat_MSGS',user:user},
success: function(data) {
console.log(data);
$('#uchatName').text(data.uchatName);
$('#uchatMsgs').html(data.uchatMsgs);
$('.chatui-window').removeClass('display-none chatui-window-close');
}
});
return false;
}


PROBLEM:



The above is what i have tried to do logically but not getting the expected results.
Any body can help me with my code what has to be done next to show the chat?










share|improve this question

























  • Guys any one can help me please?

    – MR_AMDEV
    Nov 24 '18 at 17:14
















0















I want to show chat messages between two users e.g user1 and admin(i.e currently i am) .Here is my db structure :



enter image description here



What i have tried so far:



I have a message box where messages appear, on clicking a message a username(i.e currently user1) is sent to the php for fetching chat with that user.After the chat is fetched, a chatbox is shown with the chat.



        $user        = $_POST['user'];
$db_messages = $db_readAll("messages","sender,recipient,sending_time,read_time,recipient_status","WHERE (sender='admin' OR sender=$user) AND (recipient='admin' OR recipient=$user)","ORDER BY sending_time DESC");
$uchatMsgs = '';

foreach($db_messages as $key => $message) {
$sender=$recipient='';
if($message['sender']== $_SESSION['session']){
$name = $message['recipient'];
$sender .= '<li class="m0 p0"><div class="text-center"><small>'.$ToReadableTime('@'.$message['sending_time']).'</small></div><div class="list-group-item b0 m0 mb5" style="padding:10px 10px 0 10px !important;"><div class="chatContent themed-background b-rad-30 p10 text-light">sender</div></div></li>';
}
if($message['recipient']== $_SESSION['session']){
$name = $message['sender'];
$recipient .= '<li class="m0 p0"><div class="text-center"><small>'.$ToReadableTime('@'.$message['sending_time']).'</small></div><div class="list-group-item b0 m0" style="padding:10px 10px 0 10px !important;"><div class="online-users pull-left mr5"><img src="../uploads/userprofile/default/avatar.jpg" onerror="this.onerror=null;imgDefault(this);" alt="avatar" class="online-users-img"><span title="online"></span></div><div class="chatContent bg-lightgrey b-rad-30 p10">receiver</div></div></li>';
}
$uchatMsgs = $recipient.$sender;
}
echo json_encode(['uchatName'=>$name,'uchatMsgs' => $uchatMsgs]);


HTML:



<div class="widget shadow chatui chatui-window remove-radius-bottom chatui-window-close display-none">
<div class="widget-content widget-content-mini themed-background">
<a href="javascript:void(0)" class="chatui-action-open text-dark-op pull-right"><i class="fa fa-window-restore"></i></a>
<a href="javascript:void(0)" class="chatui-action-close text-dark-op pull-right"><i class="fa fa-window-minimize" style="vertical-align:top;"></i></a>
<a href="javascript:void(0)" class="text-dark-op pull-right"><i class="fa fa-cog"></i></a>
<a href="../profiles.php" class="text-light"><strong id="uchatName"></strong></a>
</div>
<div class="widget-content widget-content-mini chatui-talk p0">
<ul id="uchatMsgs"> </ul>
</div>
<div class="widget-content widget-content-full chatui-form remove-radius-bottom">
<form action="page_app_social.html" method="post" class="m0">
<input type="text" id="chat-message" name="chat-message" class="form-control" placeholder="Type a message and hit enter..">
</form>
</div>
</div>


Jquery:



function vchat_MSGS(user){
$.ajax({
type: 'POST',
url: '../core/ajaxpdo.class.php',
dataType: 'json',
data: {page:'page_header',action:'vchat_MSGS',user:user},
success: function(data) {
console.log(data);
$('#uchatName').text(data.uchatName);
$('#uchatMsgs').html(data.uchatMsgs);
$('.chatui-window').removeClass('display-none chatui-window-close');
}
});
return false;
}


PROBLEM:



The above is what i have tried to do logically but not getting the expected results.
Any body can help me with my code what has to be done next to show the chat?










share|improve this question

























  • Guys any one can help me please?

    – MR_AMDEV
    Nov 24 '18 at 17:14














0












0








0








I want to show chat messages between two users e.g user1 and admin(i.e currently i am) .Here is my db structure :



enter image description here



What i have tried so far:



I have a message box where messages appear, on clicking a message a username(i.e currently user1) is sent to the php for fetching chat with that user.After the chat is fetched, a chatbox is shown with the chat.



        $user        = $_POST['user'];
$db_messages = $db_readAll("messages","sender,recipient,sending_time,read_time,recipient_status","WHERE (sender='admin' OR sender=$user) AND (recipient='admin' OR recipient=$user)","ORDER BY sending_time DESC");
$uchatMsgs = '';

foreach($db_messages as $key => $message) {
$sender=$recipient='';
if($message['sender']== $_SESSION['session']){
$name = $message['recipient'];
$sender .= '<li class="m0 p0"><div class="text-center"><small>'.$ToReadableTime('@'.$message['sending_time']).'</small></div><div class="list-group-item b0 m0 mb5" style="padding:10px 10px 0 10px !important;"><div class="chatContent themed-background b-rad-30 p10 text-light">sender</div></div></li>';
}
if($message['recipient']== $_SESSION['session']){
$name = $message['sender'];
$recipient .= '<li class="m0 p0"><div class="text-center"><small>'.$ToReadableTime('@'.$message['sending_time']).'</small></div><div class="list-group-item b0 m0" style="padding:10px 10px 0 10px !important;"><div class="online-users pull-left mr5"><img src="../uploads/userprofile/default/avatar.jpg" onerror="this.onerror=null;imgDefault(this);" alt="avatar" class="online-users-img"><span title="online"></span></div><div class="chatContent bg-lightgrey b-rad-30 p10">receiver</div></div></li>';
}
$uchatMsgs = $recipient.$sender;
}
echo json_encode(['uchatName'=>$name,'uchatMsgs' => $uchatMsgs]);


HTML:



<div class="widget shadow chatui chatui-window remove-radius-bottom chatui-window-close display-none">
<div class="widget-content widget-content-mini themed-background">
<a href="javascript:void(0)" class="chatui-action-open text-dark-op pull-right"><i class="fa fa-window-restore"></i></a>
<a href="javascript:void(0)" class="chatui-action-close text-dark-op pull-right"><i class="fa fa-window-minimize" style="vertical-align:top;"></i></a>
<a href="javascript:void(0)" class="text-dark-op pull-right"><i class="fa fa-cog"></i></a>
<a href="../profiles.php" class="text-light"><strong id="uchatName"></strong></a>
</div>
<div class="widget-content widget-content-mini chatui-talk p0">
<ul id="uchatMsgs"> </ul>
</div>
<div class="widget-content widget-content-full chatui-form remove-radius-bottom">
<form action="page_app_social.html" method="post" class="m0">
<input type="text" id="chat-message" name="chat-message" class="form-control" placeholder="Type a message and hit enter..">
</form>
</div>
</div>


Jquery:



function vchat_MSGS(user){
$.ajax({
type: 'POST',
url: '../core/ajaxpdo.class.php',
dataType: 'json',
data: {page:'page_header',action:'vchat_MSGS',user:user},
success: function(data) {
console.log(data);
$('#uchatName').text(data.uchatName);
$('#uchatMsgs').html(data.uchatMsgs);
$('.chatui-window').removeClass('display-none chatui-window-close');
}
});
return false;
}


PROBLEM:



The above is what i have tried to do logically but not getting the expected results.
Any body can help me with my code what has to be done next to show the chat?










share|improve this question
















I want to show chat messages between two users e.g user1 and admin(i.e currently i am) .Here is my db structure :



enter image description here



What i have tried so far:



I have a message box where messages appear, on clicking a message a username(i.e currently user1) is sent to the php for fetching chat with that user.After the chat is fetched, a chatbox is shown with the chat.



        $user        = $_POST['user'];
$db_messages = $db_readAll("messages","sender,recipient,sending_time,read_time,recipient_status","WHERE (sender='admin' OR sender=$user) AND (recipient='admin' OR recipient=$user)","ORDER BY sending_time DESC");
$uchatMsgs = '';

foreach($db_messages as $key => $message) {
$sender=$recipient='';
if($message['sender']== $_SESSION['session']){
$name = $message['recipient'];
$sender .= '<li class="m0 p0"><div class="text-center"><small>'.$ToReadableTime('@'.$message['sending_time']).'</small></div><div class="list-group-item b0 m0 mb5" style="padding:10px 10px 0 10px !important;"><div class="chatContent themed-background b-rad-30 p10 text-light">sender</div></div></li>';
}
if($message['recipient']== $_SESSION['session']){
$name = $message['sender'];
$recipient .= '<li class="m0 p0"><div class="text-center"><small>'.$ToReadableTime('@'.$message['sending_time']).'</small></div><div class="list-group-item b0 m0" style="padding:10px 10px 0 10px !important;"><div class="online-users pull-left mr5"><img src="../uploads/userprofile/default/avatar.jpg" onerror="this.onerror=null;imgDefault(this);" alt="avatar" class="online-users-img"><span title="online"></span></div><div class="chatContent bg-lightgrey b-rad-30 p10">receiver</div></div></li>';
}
$uchatMsgs = $recipient.$sender;
}
echo json_encode(['uchatName'=>$name,'uchatMsgs' => $uchatMsgs]);


HTML:



<div class="widget shadow chatui chatui-window remove-radius-bottom chatui-window-close display-none">
<div class="widget-content widget-content-mini themed-background">
<a href="javascript:void(0)" class="chatui-action-open text-dark-op pull-right"><i class="fa fa-window-restore"></i></a>
<a href="javascript:void(0)" class="chatui-action-close text-dark-op pull-right"><i class="fa fa-window-minimize" style="vertical-align:top;"></i></a>
<a href="javascript:void(0)" class="text-dark-op pull-right"><i class="fa fa-cog"></i></a>
<a href="../profiles.php" class="text-light"><strong id="uchatName"></strong></a>
</div>
<div class="widget-content widget-content-mini chatui-talk p0">
<ul id="uchatMsgs"> </ul>
</div>
<div class="widget-content widget-content-full chatui-form remove-radius-bottom">
<form action="page_app_social.html" method="post" class="m0">
<input type="text" id="chat-message" name="chat-message" class="form-control" placeholder="Type a message and hit enter..">
</form>
</div>
</div>


Jquery:



function vchat_MSGS(user){
$.ajax({
type: 'POST',
url: '../core/ajaxpdo.class.php',
dataType: 'json',
data: {page:'page_header',action:'vchat_MSGS',user:user},
success: function(data) {
console.log(data);
$('#uchatName').text(data.uchatName);
$('#uchatMsgs').html(data.uchatMsgs);
$('.chatui-window').removeClass('display-none chatui-window-close');
}
});
return false;
}


PROBLEM:



The above is what i have tried to do logically but not getting the expected results.
Any body can help me with my code what has to be done next to show the chat?







php jquery mysql chat






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 16:47







MR_AMDEV

















asked Nov 24 '18 at 16:40









MR_AMDEVMR_AMDEV

15211




15211













  • Guys any one can help me please?

    – MR_AMDEV
    Nov 24 '18 at 17:14



















  • Guys any one can help me please?

    – MR_AMDEV
    Nov 24 '18 at 17:14

















Guys any one can help me please?

– MR_AMDEV
Nov 24 '18 at 17:14





Guys any one can help me please?

– MR_AMDEV
Nov 24 '18 at 17:14












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460241%2farrange-chat-messages-based-on-sending-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460241%2farrange-chat-messages-based-on-sending-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'