PHP: Check mysql database every 10 seconds for any new rows

前端 未结 5 1835
南笙
南笙 2021-01-20 17:23

I am making a php chat and am starting the php checking database part. So when a user types something into the chat, it gets recorded in the MySQL database, how would I chec

5条回答
  •  醉话见心
    2021-01-20 18:24

    AJAX is probably the simplest solution. You can perform an AJAX request on the same page your PHP code is executing on if you really want to.

    (function check() {
        $.get('mypage.php', function(data) {
            doSomethingWith(data);
            setTimeout(check, 5000); // every 5 seconds
        });
    })();
    

提交回复
热议问题