thejagoslc Posted August 2, 2007 Share Posted August 2, 2007 I am very new at PHP, barely learning, but am looking to have a script in which I can display a word only 10 minutes out of hour for a web contest. Is that possible? I would need the 10 minutes to be random though, it can't be always the first 10 minutes.... Or maybe it would be easier to show content after 75 minutes, that way its controlled... you know what I mean? ANYONE? HELP! Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/ Share on other sites More sharing options...
simcoweb Posted August 2, 2007 Share Posted August 2, 2007 That would require the use of Cron in order to execute the script generating the page and content. Also, this would be subject to the person landing on the page during that particular time. Unless, of course, you figure a way for the number to appear or disappear without the page refreshing. PHP requires page reloads in order for the content to change. You could use some Ajax/javascript to make it work without the refresh. Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/#findComment-314457 Share on other sites More sharing options...
thejagoslc Posted August 2, 2007 Author Share Posted August 2, 2007 Actually it won't matter on the reloads.. for example, I just want a certain word to be VISIBLE during 10 minutes of each hour. Doesn't matter who is viewing it, or how many reloads they are doing. If they happend to be there during the 10 minutes that the content is AVAILABLE, then they will see it, otherwise they won't.... its to attract people to come and check the page more often to find the SECRET WORD... you know what I mean.. Thanks for all your help Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/#findComment-314458 Share on other sites More sharing options...
simcoweb Posted August 2, 2007 Share Posted August 2, 2007 Well, then you'd run a series of crons that would 1) create the secret word for display, then 2) delete the secret word. In your page you would have an 'include' for the display of the word. Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/#findComment-314464 Share on other sites More sharing options...
thejagoslc Posted August 3, 2007 Author Share Posted August 3, 2007 I don't really need to create the SECRET WORD, but I do need the code that makes it so its available only for 10 minutes of the hour. Any idea? Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/#findComment-314613 Share on other sites More sharing options...
marcus Posted August 3, 2007 Share Posted August 3, 2007 You could just use date. Say you only wanted it to show between X:20 and X:30 $minute = date("i"); if($minute >= 20 && $minute <= 30){ //show whatever } Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/#findComment-314619 Share on other sites More sharing options...
cooldude832 Posted August 3, 2007 Share Posted August 3, 2007 Why run a series of cron, instead make a script that will generate a mysql table worth of data for the day, set it to run at midnight each server day Hour minute 0 4 1 6 <?php //truncate table or make a new one here and connect to mysql $i = 0; while($i<=23){ $minuite = rand(0,60); mysql_query("Insert into `times` (minute)Values ('$minuite')") or die(mysql_error()); $i++; } ?> then simply use the tiem objects to test for each hour on the page Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/#findComment-314624 Share on other sites More sharing options...
thejagoslc Posted August 3, 2007 Author Share Posted August 3, 2007 You could just use date. Say you only wanted it to show between X:20 and X:30 $minute = date("i"); if($minute >= 20 && $minute <= 30){ //show whatever } I think this one can work.... but what I want to go around is that the word shows up only 10 minutes of the hour, but NOT the same 10 minutes of EVERY HOUR. am trying this, but its obviously wrong.... any help? <? $minute = date("H:i"); if ($minute >= 01:01 && $minute <= 01:11) { ?>ONE WORD <? } else if ($minute >= 02:21 && $minute <= 02:31) { ?>SECOND WORD <? } else { ?>NO WORD AVAILABLE <? } ?> I really appreciate it guys!! Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/#findComment-314658 Share on other sites More sharing options...
thejagoslc Posted August 3, 2007 Author Share Posted August 3, 2007 I FIGURE IT OUT!!! WHOOOOHO!!! ;D ;) Here is how am doing it.... <? $h = date('H'); //H is set to 24 hours 00 - 23 $m = date('i'); //i is set to 60 minutes 00 - 59 $h = $h+1; //I set the time so it matches the local visitors. if ($h == 00 && $m >= 00 && $m <= 15) echo $usa_code; else if ($h == 01 && $m >= 05 && $m <= 20) echo $usa_code; else if ($h == 02 && $m >= 10 && $m <= 25) echo $usa_code; else if ($h == 03 && $m >= 15 && $m <= 30) echo $usa_code; else if ($h == 04 && $m >= 20 && $m <= 35) echo $usa_code; else if ($h == 05 && $m >= 25 && $m <= 40) echo $usa_code; else if ($h == 06 && $m >= 30 && $m <= 45) echo $usa_code; else if ($h == 07 && $m >= 35 && $m <= 50) echo $usa_code; else if ($h == 08 && $m >= 40 && $m <= 55) echo $usa_code; else if ($h == 09 && $m >= 45 && $m <= 59) echo $usa_code; else if ($h == 10 && $m >= 00 && $m <= 15) echo $usa_code; else if ($h == 11 && $m >= 05 && $m <= 20) echo $usa_code; else if ($h == 12 && $m >= 10 && $m <= 25) echo $usa_code; else if ($h == 13 && $m >= 15 && $m <= 30) echo $usa_code; else if ($h == 14 && $m >= 20 && $m <= 35) echo $usa_code; else if ($h == 15 && $m >= 25 && $m <= 40) echo $usa_code; else if ($h == 16 && $m >= 30 && $m <= 45) echo $usa_code; else if ($h == 17 && $m >= 35 && $m <= 50) echo $usa_code; else if ($h == 18 && $m >= 40 && $m <= 55) echo $usa_code; else if ($h == 19 && $m >= 45 && $m <= 59) echo $usa_code; else if ($h == 20 && $m >= 00 && $m <= 15) echo $usa_code; else if ($h == 21 && $m >= 05 && $m <= 20) echo $usa_code; else if ($h == 22 && $m >= 10 && $m <= 25) echo $usa_code; else if ($h == 23 && $m >= 15 && $m <= 30) echo $usa_code; else echo '<small>...NO CODE RIGHT NOW!</small>'; ?> Link to comment https://forums.phpfreaks.com/topic/63115-solved-can-i-display-content-only-10-random-min-of-each-hour/#findComment-314689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.