【问题标题】:My countdown doesnt start on my betting site我的投注网站没有开始倒计时
【发布时间】:2016-05-04 10:43:50
【问题描述】:

我有一个 csgo 投注网站,当至少 2 名玩家将他们的皮肤存入该网站时,游戏开始,机器人需要 2 分钟才能选出获胜者。

一切正常,游戏开始,游戏开始后 2 分钟选出获胜者,但本应显示剩余秒数的倒计时文本不起作用。

这是我的代码Time left: <h4 id="countdown-timer"><span id="timeleft">0</span></h4>

已接受 XXXXXXX (XXXXXXXXXXXXXX) 的交易报价 #1211760373 当前玩家:1 已接受 XXXXXXXXX (XXXXXXXXXXXXXXX) 的交易报价 #1211760308 当前玩家:2 找到 2 名玩家

这就是机器人所说的

这是timeleft.php http://prnt.sc/b03ute

PHP 代码

<?php
@include_once ("set.php");
$game = fetchinfo("value", "info", "name", "current_game");
$r = fetchinfo("starttime", "games", "id", $game);
$somebodywon = fetchinfo("winner", "games", "id", $game);
if ($r == 2147483647)
    die("120");
$r += 120 - time();
if ($r < 0) {
    $r = 0; /* if(empty($somebodywon)) include_once('getwinner34634f.php'); */
} echo $r;
?>

也找到了这个,叫做 ssetimeleft.php

<

?php
@include_once ("set.php");
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache'); // recommended to prevent caching of event data.

/**
 * Constructs the SSE data format and flushes that data to the client.
 *
 * @param string $id Timestamp/id of this connection.
 * @param string $msg Line of text that should be transmitted.
 */
function sendMsg($id, $msg) {
  echo "id: $id" . PHP_EOL;
  echo "data: $msg" . PHP_EOL;
  echo PHP_EOL;
  ob_flush();
  flush();
}
while (1) {
    $game = fetchinfo("value","info","name","current_game");
    $r = fetchinfo("starttime","games","id",$game);
    if($r == 2147483647){
        $var=120;
    }else{
        $var = $r += 120-time();
        if($r < 0)
        {
            $var = 0;
            /*if(empty($somebodywon))
                include_once('getwinner34634f.php');*/
        }
    }
    sendMsg(time(),$var);
    usleep(500000); //1000000 = 1 seconds

}
?>

【问题讨论】:

  • 请提供更新时间显示文本的代码。 (可能是 javascript?)
  • 请使用此代码更新您的问题,使其更具可读性。
  • 我刚做了,你知道怎么帮我吗?

标签: php mysql node.js steam


【解决方案1】:

如果没有更多信息,很难在此处看到您要执行的操作,但是 PHP 文件中的 time() 函数仅在服务器端 PHP 处理器处理此文件时运行。但是倒计时显示是应该在客户端处理的。

我建议添加一个 javascript 或 jQuery 文件来为您处理倒计时显示。

【讨论】:

  • 我不知道如何从头开始编写这样的代码,是吗?
【解决方案2】:

试试这是一个非常基本的例子:

$(function() {
  var time_out = 10;
  var timeout = setInterval(calculate, 1000);

  function calculate() {
    $('#timeleft').text(time_out--);
    if (time_out < 0) {
      clearInterval(timeout);
    }
  }
});
<!DOCTYPE html>
<html>

<head>
  <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>

<body>
  <h4 id="countdown-timer"><span id="timeleft">0</span></h4>
</body>

</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多