dongyanhu5628 2016-01-08 12:44
浏览 23

关于DB和span类

I've just started to learn programming to be able to do changes to my site so i dont know much yet.

My question is I have this script:

<h4 style="border-radius: 0px 0px 0px 0px;"><?php echo $winnername ?></h4>
<span class="val"><?php echo $msg[$lang]["win"]; ?>:</span>
<span class="price">$<?php echo round($winnercost,2); ?></span>

Is it possible to make it auto update when a new winner is chosen, because now you have to reload site for it to update.

This is the first part where it grabs info

<?php 
        $lastgame = fetchinfo("value","info","name","current_game");
        $lastwinner = fetchinfo("userid","games","id",$lastgame-1);
        $winnercost = fetchinfo("cost","games","id",$lastgame-1);
        $winnerpercent = round(fetchinfo("percent","games","id",$lastgame-1),1);
        $winneravatar = fetchinfo("avatar","users","steamid",$lastwinner);
        $winnername = fetchinfo("name","users","steamid",$lastwinner);
?>
  • 写回答

2条回答 默认 最新

  • dongping9475 2016-01-08 12:54
    关注

    PHP only generates a page server-side and sends them to the client. Auto refreshing the generated page is managed client-side, so you must use Javascript for this.

    You will use Ajax for auto refreshing part of the page. Create a PHP script that only returns the new data (the html content for the tag <h4>), and use something like this script from another question.

    If you use that script, instead of using onclick to fire the refresh, you can call it automatically using setInterval():

    <script>
      setInterval(function() {
        getSummary();
      },60000);
    </script>
    

    This will refresh the data every minute.

    评论

报告相同问题?