开发者

Partial PHP code refresh

开发者 https://www.devze.com 2023-01-01 04:10 出处:网络
Is it possible to refresh only the part of the page? How? the part: if (checkExpiry($member->expires)==true) {

Is it possible to refresh only the part of the page? How?

the part:

if (checkExpiry($member->expires)==true) {
    print timeLeft($leftts);
} else {
    print "expired";
}

I have table which is showing name, email, time until membership ends and I need to refresh 'time until membership ends' every seco开发者_JS百科nd.


You can check out AJAX, where Javascript calls a PHP application of yours an updates only a certain part of the site.


I presume you mean "refresh the page". The answer is not directly. PHP is executed on the server and "normal" HTTP doesn't do server side pushes. This means that once a page is sent to a client, it won't reload unless something or someone on the client asks for it again.

To implement this, you're going to have to, as Ólafur suggested, use some Javascript on the client side to check the timer and then reload the page (or part of it if you prefer) using an AJAX style call.


If you use Javascript, you can do like this:

<script src="jquery.js"></script>
<script>
$(document).ready(function()
{
   //time_to_expire.php is called every second to get time from server
   var refreshId = setInterval(function()
   {
     $('#expire').load('time_to_expire.php?userID=<? echo $userID; ?>);
   }, 1000);
});
</script>

inside time_to_expire.php you'll put your code to provide the time remaining to expire the user account!

Note that in that example I'm sending a variable "userID" that will contain the user ID for properly retrieve data from the time_to_expire.php file...

Hope it helps or give's you an idea... :)

0

精彩评论

暂无评论...
验证码 换一张
取 消