更平滑的聊天应用程序 [英] A smoother chat application
问题描述
我已经使用PHP,MySQL和jQuery的,Ajax和其他国家发出一个聊天应用程序。
I have made a chat application using PHP, MySQL, Jquery, Ajax and the rest.
有一个HTML表单的员额数据(聊天)使用MySQL(PHP)和Ajax到我的数据库。
There is a html form that posts data (the chat) using Mysql (PHP) and Ajax to my database.
然后我有一个 $(文件)。就绪
jQuery的事件,AJAX加载数据库的电流id(旧标识)。
I then have a $(document).ready
jquery event with ajax that loads the current id (the old id) of the database.
我也有一个间隔功能,每3秒阿贾克斯,获取当前ID(新ID)。
I also have an interval function every 3 seconds with ajax that gets the current id (the new id).
如果旧ID不等于新的ID。我加载使用AJAX整个数据库。并用新的ID替换旧的ID。
If the old id doesn't equal the new id. I load using ajax the whole database. and replace the old id with the new id.
这一切给人的感觉非常凌乱给我。谁能推荐一个不同的方法(与利弊),要做到这一点,无论多么大或小的变化?
This all feels very messy to me. Can anyone recommend a different method (with pros and cons) to do this, no matter how big or small the change?
例如:
- 在不同的方法来获取整个数据库装载(不使用 数据库的ID)[小的变化] - 易做将需要一个小时
- 在使用插座[大变革] - 很难做到将带你2周
- A different method to getting the whole database to load (not using the id of the database) [small change] - Easy to do will take 1 hour.
- using sockets [big change] - Hard to do will take you 2 weeks.
推荐答案
尝试使用LIMIT和OFFSET在SQL语句中拔出只有新的记录:如SELECT * FROM帖子ORDER BY的post_id降序限制{$限制} OFFSET {$抵消}
,其中:
Try using LIMIT and OFFSET in your SQL statement to pull out only the new records: e.g. "SELECT * FROM posts ORDER BY post_id DESC LIMIT {$limit} OFFSET {$offset}"
, where:
-
结果$限额
=该号码提取(新的职位有多少呢?) -
$抵消
=第一篇文章检索
$limit
= The number of results to retrieve (how many new posts are there?)$offset
= First post to retrieve
示例: 如果最后一个帖子ID为50,并在你的下一个检查是56,试试这个:
Example: If the last post ID was 50, and on your next check it is 56, try this:
SELECT * FROM帖子ORDER BY的post_id DESC LIMIT 6 OFFSET 51
这篇关于更平滑的聊天应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!