Jump to content

[SOLVED] CAN I DISPLAY CONTENT ONLY 10 random MIN of each HOUR?


thejagoslc

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

I FIGURE IT OUT!!! WHOOOOHO!!! ;D ;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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.