如何完成一个滚动聊天室的制作?
我正在为我的网站编写一个聊天室,但我遇到了一个很长的障碍。希望你们都可以帮助我 =)
无论如何,我想知道是否有一种方法可以操纵 MySQL 或 PHP 使它们向后返回信息。我尝试过使用 ORDER BY ASC 和 DESC...但没有成功。我的聊天室自动滚动到底部,我希望聊天的最新回复出现在框中的最后,然后让较早的回复向上逐渐消失。有点像 Facebook 聊天。关于我如何实现这一目标有什么想法吗? :/
谢谢!
I am programming a chatroom for my website, and I've came a long a bi of a snag. Hopefully you all can help me =)
Anyway, I am wondering if there is a way to manipulate MySQL or PHP to make them return information backwards. I have tried using ORDER BY ASC and DESC... with no success. My chatroom automatically scrolls to the bottom and I want the chat's most recent reply to appear very last in the box, and then have the earlier replies trail off upward. Kind of like Facebook chat. Any ideas as to how I could accomplish this? :/
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 php 中,在输出之前只需对消息列表执行
array_reverse
即可。这里有文档 http://php.net/manual/en/function。数组反转.php
In php before the output just do an
array_reverse
on the list of messages.Here you have the documentation http://php.net/manual/en/function.array-reverse.php
您可以安装像 this 这样的 jQuery 插件,然后使用如下内容:
这假设您将每个消息元素的
title
设置为该消息发送时的时间戳。尽管我只是将非标准属性(即timtestamp
)附加到每个消息标记,但是您可以使用:You could install a jQuery plugin like this, then use something like:
This assumes that you set the
title
of each message element to be the timestamp of when that message is sent. Though I would just attach a non-standard attribute i.e.timtestamp
to each message tag, then you would use: