Page 1 of 1

Inverval Of Time

Posted: Wed Mar 08, 2006 3:24 pm
by Pineriver
Ok, I have a question on how to do an interval program.
This is what I would like, have some text on a webpage display for X amount of seconds at X amount of seconds in between . Seems simple enough but I was hoping to do it without a database. This is what I have come up with so far..

Code: Select all

$ShowLength=5; # Amount of seconds to show on the page, after this is up stop displaying
$StartBase="946702800"; # The unix base date to work with, Jan 1st 2000 00:00:00

$Interval =40; # Amount of seconds between displays 

/*
It should be global, meaning that everyone sees this on the page 
at the same time so no COOKIES or SESSIONS 
*/

$VarLTime=time()-$ShowLength;

if(time()-$ShowLength  <  ($StartBase * something )+$ShowLength something  )echo "Text";
This possible? Thanks in advance

Posted: Wed Mar 08, 2006 3:58 pm
by feyd
seems like you two need to talk:

viewtopic.php?t=45101

re

Posted: Wed Mar 08, 2006 5:19 pm
by Pineriver
Thanks but thats not going to work for me, since its an interval for every X amount of seconds and not a set start end time I cant use mktime since the minutes , hours , days are changing.
So if I have an interval greater then 60 seconds the int minute in mktime() keeps updating spoiling my update frequency.

Code: Select all

$Interval =120;
$sec = ($Interval >= 60)? 0 : $Interval;
$end= mktime(date(H),date(i)+floor($Interval / 60),$sec);
Its easy to print out between specific times but to have a X amount of seconds interval between the display times.

Makes sense?

got it

Posted: Thu Mar 09, 2006 6:10 pm
by Pineriver
If anyones been keeping up on this thread, I figured it out.
formula
Figure out the amount of intervals between a set time and the current time
ceil() that number off to the highest number
Multiply that number with the interval and you will get a ending time that we can use.

Code: Select all

$ShowLength=10;
$StartBase="946702800";
$Interval =120;

$Sub =time()-$StartBase;

$HowMany = $Sub /$Interval;
$Ceil=ceil($HowMany);
$AbovePlus =($Ceil*$Interval)+$StartBase;
$show_message = ($AbovePlus-$ShowLength) < time();

echo "
$Sub  =  How many seconds are there between time() and base
".ceil($HowMany)." = How many + 1 intervals are there in Sub
".time()." = time()
$AbovePlus = The End 
".var_dump($show_message)."
";
# When $show_message returns true, we display the message :)