-1

计时器 java 脚本在本地服务器上运行良好。但是当我在托管服务器上运行它时,它不会启动计时器。

<script type="text/javascript" >
<?php
    $elapsed=time()-strtotime($_SESSION['starttime']);
    if(((int)$elapsed/60)<(int)$_SESSION['duration'])
    {
        $result=executeQuery("SELECT " .
        " TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%H') as hour, ".
        " TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%i') as  min, ".
        " TIME_FORMAT(TIMEDIFF(endtime,CURRENT_TIMESTAMP),'%s') as sec ".
        " FROM studenttest ".
        " WHERE stdid=".$_SESSION['stdid'].
        " AND testid=".$_SESSION['testid'].";");
        if($rslt=mysql_fetch_array($result))
        {
            echo "var hour=".$rslt['hour'].";";
            echo "var min=".$rslt['min'].";";
            echo "var sec=".$rslt['sec'].";";
        } else {
            $_GLOBALS['message']="Try Again";
        }
        closedb();
    } else {
        echo "var sec=01;var min=00;var hour=00;";
    }
?>
</script>
4

2 回答 2

0

代替

<?php

<?php
session_start();
于 2012-04-27T11:34:50.630 回答
0

进一步清理代码后,堆栈溢出的代码高亮显示您的 php 输出被注释标记包围:

<!-- -->

所以javascript永远不会看到PHP回显的变量。这可能是你的问题吗?

于 2012-04-27T19:02:51.353 回答