Page 1 of 1

making certain pics appear at certain times of the day?

Posted: Mon May 13, 2002 12:48 pm
by AndyPugh
Hi,

Im wondering if anyone can help me with this little problem.

Were Currently setting up a website for a radio station due to launch in a few weeks time (http://www.castlefm.net)

What I need help with is, were wanting a script that puts a pic and info up of the presenter who is online at a specific time. like a pic for the 7 - 9am show then when it hits 9am it will change to a pic of the 9 - 12 am presenter? is this possible? have a look at the site and you will get a better drift of what im talking about.

Any help you can offer would be much appreciated.

Best Regards - Andy Pugh
Interactive Media Manager - (castle FM)

Posted: Mon May 13, 2002 3:30 pm
by enygma
yeah, just have a database table with something like:
image_name
hour

and then use time() and date() to get the current hour when the page loads, then just

select image_name from table where hour='".$hour."'";

or something similar. then, when the page loads, it looks at the database to see which file it needs to load up.

There's tons of ways to do this, and that's just a suggestion...
-enygma

Posted: Mon May 13, 2002 9:20 pm
by lc
Yup that's how I'd do it... like

Code: Select all

$hour = date(G);

if ($hour == "13"){
$image = "the_image.jpg";
}
sorta thing.

Posted: Mon May 13, 2002 10:11 pm
by volka
to simply map the hour of the day to a picture without a database you may use (i.e.)

Code: Select all

$today = getdate();
$picname = 'pic'.$todayї'hours'].'gif';
if you'd like to map it more exact try this SELECT (mysql):

Code: Select all

CREATE TABLE `scheme` (`picture` char(30) default '0', `fromTime` time default NULL);

Code: Select all

$query = 'SELECT a.picture, a.fromTime, max(b.fromTime) as mt from scheme a, scheme b WHERE b.fromTime <= "'.$time.'" group by a.fromTime having(a.fromTime = mt)'
since I'm not very familiar with SQL there is probably a shorter way to perform the SELECT but this should return the name of the current picture as first element of your result. for the table definition above $time should be like "06:13:59" hh:mm:ss
for a weekly scheme you may extend the where-clause with a ....AND wday='.getdate()['wday']....

Posted: Mon May 13, 2002 11:10 pm
by Tiimmy
Another good method you could use, perhaps to display if the sun is rising or setting, would be kinda like this:

Code: Select all

<?php
$time = date(G);
if ($time => "5" && <= "8") &#123;
    return "<img src="SUNRISE_IMAGE.PNG">";
&#125;
elseif ($time => "11" && <= "13") &#123;
    return "<img src="MIDDAY_IMAGE.PNG">";
&#125;
elseif ($time => "15" && <= "18") &#123;
    return "<img src="SUNSET_IMAGE.PNG">";
&#125;
elseif ($time => "23" && <= "1") &#123;
    return "<img src="MIDNIGHT_IMAGE.PNG">";
&#125;
?>
Of course you'd have to change the hours depending on your timezone... :P :oops: :lol: :twisted:

Posted: Wed May 15, 2002 6:54 pm
by AndyPugh
Yes Im looking for something like that, I tried that one but kept getting errors, did I need to make a database to go with it? I would need it to be like .

Code: Select all

<?php
$time = date(G);
if ($time => "7" && <= "9") &#123;
    return "<img src="morningpresenter.jpg">";
&#125;
elseif ($time => "9" && <= "12") &#123;
    return "<img src="midmorningpresenter.jpg">";
&#125;
elseif ($time => "12" && <= "14") &#123;
    return "<img src="lunchtimepresenter.jpg">";
&#125;
elseif ($time => "14" && <= "18") &#123;
    return "<img src="afternoonpresenter.jpg">";
&#125;
elseif ($time => "18" && <= "20") &#123;
    return "<img src="dinnertimepresenter.jpg">";
&#125;
elseif ($time => "20" && <= "21") &#123;
    return "<img src="danceshow.jpg">";
&#125;
elseif ($time => "21" && <= "23") &#123;
    return "<img src="earlyeveningpresenter.jpg">";
&#125;
elseif ($time => "23" && <= "1") &#123;
    return "<img src="latenightpresenter.jpg">";
&#125;
?>
Is something like that Possible, I cant get it to work!

Posted: Wed May 15, 2002 8:03 pm
by volka
quiet ;)

Code: Select all

<?php
function getImageName()
&#123;
$hour = getdate(); // current time as array 
$hour = $hour&#1111;'hours']; // and from there the hours-Element
if ($hour<7)
&#123;
   if ($hour==0 || $hour == 1)  // 
     return 'latenightpresenter.jpg';
   else
     return 'transmissionbreak.jpg'; // I suppose
&#125;
elseif ($hour <= 9)
   return 'morningpresenter.jpg'; 
elseif ($hour <= 12) 
   return 'midmorningpresenter.jpg'; 
elseif ($hour <= 14) 
   return 'lunchtimepresenter.jpg'; 
elseif ($hour <= 18) 
    return 'afternoonpresenter.jpg'; 
elseif ($hour <= 20) 
   return 'dinnertimepresenter.jpg'; 
elseif ($hour <= 21) 
   return 'danceshow.jpg'; 
else ($hour <= 23) 
   return 'earlyeveningpresenter.jpg'; 
&#125;

print '<img src="'.getImageName().'"/>';
?>
I'm not quiet sure about the meaning <= in your code. In mine 'morningpresenter.jpg' would be presented from 7:00 to 9:59 and 'latenightpresenter.jpg' from 0:00 to 1:59.
But since ...elseif ($time => "23" && <= "1") {... suggests a 'clockwise-arithmetic ' you might want 'morningpresenter.jpg' shown from 7:00 to 9:00 (or 8:59?). If so, replace '<=' by '<' (the condition for ''transmissionbreak' must be changed too).

Posted: Thu May 16, 2002 2:14 pm
by AndyPugh
ok that works, but.. not in my time zone, is there some kinda time offset code i could use to set it to GMT/BST ?

Thanks for everyones help so far! it has been a big help!

Posted: Thu May 16, 2002 2:18 pm
by fatal
The Data function( http://www.php.net/manual/en/function.date.php ) has timezone functions.

Posted: Thu May 16, 2002 3:46 pm
by AndyPugh
Ok i fixed the times up

lol final request!
how do I print there names below the pics?

Code: Select all

<?php
function getImageName()

&#123; 

$hour = getdate(); // current time as array 

$hour = $hour&#1111;'hours']; // and from there the hours-Element 

if ($hour<7) 

&#123; 

   if ($hour==16 || $hour == 17)  // 

     return 'latenightpresenter.jpg'; 

   else 

     return 'transmissionbreak.jpg'; //

&#125; 

elseif ($hour <0) 

   return 'morningpresenter.jpg';

elseif ($hour <1) 

   return 'morningpresenter.jpg'; 

elseif ($hour <2) 

   return 'midmorningpresenter.jpg'; 

elseif ($hour <3) 

   return 'midmorningpresenter.jpg'; 

elseif ($hour <4) 

   return 'midmorningpresenter.jpg'; 

elseif ($hour <5) 

   return 'lunchtimepresenter.jpg'; 

elseif ($hour <6) 

   return 'lunchtimepresenter.jpg'; 

elseif ($hour <7) 

    return 'afternoonpresenter.jpg'; 

elseif ($hour <8) 

    return 'afternoonpresenter.jpg'; 

elseif ($hour <9) 

    return 'afternoonpresenter.jpg'; 

elseif ($hour <10) 

    return 'afternoonpresenter.jpg'; 

elseif ($hour <11) 

   return 'dinnertimepresenter.jpg'; 

elseif ($hour <12) 

   return 'dinnertimepresenter.jpg'; 

elseif ($hour <13) 

   return 'danceshow.jpg'; 

elseif ($hour <14)

   return 'earlyeveningpresenter.jpg';

elseif ($hour <15)

   return 'earlyeveningpresenter.jpg';

&#125; 



print '<img src="'.getImageName().'"/>'; 

?>

Posted: Thu May 16, 2002 4:57 pm
by volka
hmmm.....try

Code: Select all

function getImageName() 
&#123; 
$hour = getdate(); // current time as array 
$hour = $hour&#1111;'hours']; // and from there the hours-Element 
...
elseif ($hour <1) 
   return array('morningpresenter.jpg', 'the morning show'); 
elseif ($hour <2) 
...
&#125;

$desc = getImageName();
print '<span><img src="'.$desc&#1111;0].'"/><br/>'.$desc&#1111;1].'</span>';
and perhaps a little bit CSS

Posted: Sat May 18, 2002 6:27 pm
by AndyPugh
Great that works fine! its all up and working on the site now http://www.castlefm.net

Final Final Final request i Have for this script is, How would i get it to change for the weekend? we have the same presenters on during the week but at the weekend they change over... is there anyway I can tell the script to read a saturday.php file and a sunday.php file when those days come? here is the script for the weekdays

Code: Select all

<?php
function getImageName()

&#123; 

$hour = getdate(); // current time as array 

$hour = $hour&#1111;'hours']; // and from there the hours-Element 

if ($hour<7) 

&#123; 

   if ($hour==24 || $hour == 0)  // 

     return 'latenightpresenter.jpg'; 

   else 

     return 'transmissionbreak.jpg'; //

&#125; 

elseif ($hour <1) 

   return array ('morningpresenter.jpg','Maurice Taggart');

elseif ($hour <2) 

   return array ('morningpresenter.jpg','Maurice Taggart'); 

elseif ($hour <3) 

   return array ('midmorningpresenter.jpg','Justin Macartney'); 

elseif ($hour <4) 

   return array ('midmorningpresenter.jpg','Justin Macartney'); 

elseif ($hour <5) 

   return array ('midmorningpresenter.jpg','Justin Macartney'); 

elseif ($hour <6) 

   return array ('lunchtimepresenter.jpg','Kenny Davis'); 

elseif ($hour <7) 

   return array ('lunchtimepresenter.jpg','Kenny Davis'); 

elseif ($hour <8) 

    return array ('afternoonpresenter.jpg','Stuart Robinson'); 

elseif ($hour <9) 

    return array ('afternoonpresenter.jpg','Stuart Robinson'); 

elseif ($hour <10) 

    return array ('afternoonpresenter.jpg','Stuart Robinson'); 

elseif ($hour <11) 

    return array ('afternoonpresenter.jpg','Stuart Robinson'); 

elseif ($hour <12) 

   return array ('dinnertimepresenter.jpg','Simon Barr'); 

elseif ($hour <13) 

   return array ('dinnertimepresenter.jpg','Simon Barr'); 

elseif ($hour <14) 

   return array ('danceshow.jpg','Colin Kennedy'); 

elseif ($hour <15)

   return array ('earlyeveningpresenter.jpg','Lisa McCormick');

elseif ($hour <16)

   return array ('earlyeveningpresenter.jpg','Lisa McCormick');

elseif ($hour <17)

   return array ('latenightpresenter.jpg','Mark McCloud<br>Late Show');

elseif ($hour <18)

    return array ('latenightpresenter.jpg','Mark McCloud<br>Late Show');

elseif ($hour <19)

   return array  ('transmissionbreak.jpg','Citybeat 96.7 FM');

elseif ($hour <20)

   return array  ('transmissionbreak.jpg','Citybeat 96.7 FM');

elseif ($hour <21)

   return array  ('transmissionbreak.jpg','Citybeat 96.7 FM');

elseif ($hour <22)

  return array  ('transmissionbreak.jpg','Citybeat 96.7 FM');

elseif ($hour <23)

   return array  ('transmissionbreak.jpg','Citybeat 96.7 FM');

elseif ($hour <7)

   return array  ('transmissionbreak.jpg','Citybeat 96.7 FM');

&#125; 



$desc = getImageName(); 
print '<span><img src="'.$desc&#1111;0].'"/><br/>'.$desc&#1111;1].'</span>';

?>

Posted: Sat May 18, 2002 6:38 pm
by volka
The array returned by getdate has an element 'wday' numerically representing the current day of the week.

Code: Select all

...$date=getdate(); 
switch($date&#1111;'wday'])
&#123;
   case 0: case 6:
     weekend();
     break;
   default:
     weekday();
&#125;