PHP动态计数器?
我在网上找到了这个脚本,我需要修改它以满足我的需要,并且我已经尝试了一些东西,但我无法理解。
我找到的脚本位于此处: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下面是计算 8 月 22 日到现在有多少“点”的 PHP:
Here's the PHP to calculate how many "points" between Aug 22 and now:
基本上是这样的:
一开始我很难理解这些问题,所以我希望这就是你想要的。
基本上用php制作一个starttime,然后使用javascript和随机数,只要页面启动就增加数字。
如果需要,请将 Math.floor() 替换为静态数字。
Basically something like this:
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.