PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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..
$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";
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.
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.
$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 :)