PHP动态计数器?

发布于 2024-12-01 01:04:34 字数 1866 浏览 2 评论 0原文

我在网上找到了这个脚本,我需要修改它以满足我的需要,并且我已经尝试了一些东西,但我无法理解。

我找到的脚本位于此处: http://www.daniweb.com/web -development/php/threads/68355

我需要一个类似的脚本,基本上以数字 32000 开头(基于 8 月 22 日午夜),然后每 10 增加 5分钟永远。

任何人都可以帮助我使用该示例吗?或者给我指出其他地方现有的例子?

非常感谢!我已从下面包含的链接粘贴了代码:

<?php

$now = time();
$start = mktime(0, 0, 0, 1, 24, 2007);
$carbonsaving =((($now - $start) * 0.0058774) + 130000);
$format = round($carbonsaving, 2);
// in this example
// $now = a unix timestamp of this very second
// $start is the date that you want the counter to start from sent over //as a unix     timestamp
// $carbonsaving is the calculation that you want to perform to get //your base figure
// i.e. total saving = ((date now - start date)* growth rate) + base rate
// this gives us the starting saving all that needs to be done is increment it with     javascript
?>

<script type="text/javascript">
// we need to import our server side variable into javascript to let it increment live

var car = <?php print($format); ?>;
var rou

function incs()
{
car = car + 0.01;
rou = Math.round(car*100)/100
document.getElementById("carb").innerHTML=rou;
}
// what function incs does is take car and adds 0.01 to it
//rou rounds the figure to 2 dp
//the document.getElementById("carb") can refer to a <p> tag //<span> or whatever and just     says with .innerHTML=rou; that the //value between the results of rou
//hope this helps
//Nicholas King
//ecotricity
</script>
</head>
<!-- body onload setInterval tells the page to load our javascript function and repeat it by     every x microseconds, so this repeats every 2 seconds //-->
<body onload="setInterval('incs()', 2000)">
<div id="carb">Calculating...</div>

I found this script online and I need to modify it to fit my needs and I've tried some stuff, but I'm in over my head.

The script I found is located here: http://www.daniweb.com/web-development/php/threads/68355

I need a similar script that basically will start with the number 32000 (based on let's say midnight on August 22nd), and then go up by 5 every 10 minutes forever.

Can anyone help me using that example? Or point me to an existing example elsewhere?

Thanks so much! I've pasted the code from my included link below:

<?php

$now = time();
$start = mktime(0, 0, 0, 1, 24, 2007);
$carbonsaving =((($now - $start) * 0.0058774) + 130000);
$format = round($carbonsaving, 2);
// in this example
// $now = a unix timestamp of this very second
// $start is the date that you want the counter to start from sent over //as a unix     timestamp
// $carbonsaving is the calculation that you want to perform to get //your base figure
// i.e. total saving = ((date now - start date)* growth rate) + base rate
// this gives us the starting saving all that needs to be done is increment it with     javascript
?>

<script type="text/javascript">
// we need to import our server side variable into javascript to let it increment live

var car = <?php print($format); ?>;
var rou

function incs()
{
car = car + 0.01;
rou = Math.round(car*100)/100
document.getElementById("carb").innerHTML=rou;
}
// what function incs does is take car and adds 0.01 to it
//rou rounds the figure to 2 dp
//the document.getElementById("carb") can refer to a <p> tag //<span> or whatever and just     says with .innerHTML=rou; that the //value between the results of rou
//hope this helps
//Nicholas King
//ecotricity
</script>
</head>
<!-- body onload setInterval tells the page to load our javascript function and repeat it by     every x microseconds, so this repeats every 2 seconds //-->
<body onload="setInterval('incs()', 2000)">
<div id="carb">Calculating...</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只想待在家 2024-12-08 01:04:34

下面是计算 8 月 22 日到现在有多少“点”的 PHP:

$start = mktime(0, 0, 0, 8, 22, 2011); // Aug 22, 2011
$diff = time() - $start; // seconds between start and now
$extra = 5 * floor($diff / 600);
$result = 32000 + $extra;

Here's the PHP to calculate how many "points" between Aug 22 and now:

$start = mktime(0, 0, 0, 8, 22, 2011); // Aug 22, 2011
$diff = time() - $start; // seconds between start and now
$extra = 5 * floor($diff / 600);
$result = 32000 + $extra;
眼泪也成诗 2024-12-08 01:04:34

基本上是这样的:

$now = time();
$start = mktime(0, 0, 0, 1, 24, 2007);
$init =((($now - $start)) + 130000);
?>

<script type="text/javascript">

var init = <?php print($init); ?>;
var val

function incs()
{
    //Increase by random number (4-6)
    init = init + Math.floor( (Math.random()*4)+3);
    document.getElementById("counter").innerHTML=init;

    //Create a random timer to make it not so obvious.

    var random_timer = Math.floor( (Math.random()*500)+2000);
    setTimeout('incs()',random_timer );
}

</script>
</head>
<body onload="">
    <div id="counter">Calculating...</div>
</body>

一开始我很难理解这些问题,所以我希望这就是你想要的。
基本上用php制作一个starttime,然后使用javascript和随机数,只要页面启动就增加数字。
如果需要,请将 Math.floor() 替换为静态数字。

Basically something like this:

$now = time();
$start = mktime(0, 0, 0, 1, 24, 2007);
$init =((($now - $start)) + 130000);
?>

<script type="text/javascript">

var init = <?php print($init); ?>;
var val

function incs()
{
    //Increase by random number (4-6)
    init = init + Math.floor( (Math.random()*4)+3);
    document.getElementById("counter").innerHTML=init;

    //Create a random timer to make it not so obvious.

    var random_timer = Math.floor( (Math.random()*500)+2000);
    setTimeout('incs()',random_timer );
}

</script>
</head>
<body onload="">
    <div id="counter">Calculating...</div>
</body>

I had some difficulty grasping the questions at first, so i hope this is what you were after.
Basically make a starttime, with php, then use javascript and random numbers to increase the number as long as the page is up.
replace the Math.floor() with static number if you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文