Jump to content

Request Changer


Recommended Posts

hi there folks i'm looking for some sort of script

were it will change my little scripts over at a certain time and day from the autodj request button to my dj's request buttons. here's an example

 

6pm till 12am

http://www.destiny106.co.uk/djonair/reqs/rabbit.png

 

12am till 4pm

http://destiny106.co.uk/djonair/reqs/devil.png

 

and so it goes on if anyone could help that would be great

Link to comment
Share on other sites

In PHP, this should work:

 


if (date('G') >= 18)
{
  //It is 6pm or later but not past midnight
  echo "http://www.destiny106.co.uk/djonair/reqs/rabbit.png";
}
else if (date('G') >= 0 && date('G') {
  //It is 12am or later, but not later than 3:59
  echo "http://destiny106.co.uk/djonair/reqs/devil.png";
}
else
{
  //Does not match either timeframe
  echo "Outside the range of options. Current time is: ".date('g:i A').".";
}

?>

Link to comment
Share on other sites

ok thanks i have changed the timing in the php script to GMT timing

 

but what if i want to add more request buttons. what do i copy and paste in the code?

 

and how do i now if the code will change from one request button to the other

Link to comment
Share on other sites

Add more "else if" statements after:

 

 
if (date('G') >= 18)
{
  //It is 6pm or later but not past midnight
  echo "http://www.destiny106.co.uk/djonair/reqs/rabbit.png";
}
else if (date('G') >= 0 && date('G') {
  //It is 12am or later, but not later than 3:59
  echo "http://destiny106.co.uk/djonair/reqs/devil.png";
}

like so:

else if (date('G') >= 4 && date('G') {
  //It is 4am or later, but not later than 7:59
  echo "http://destiny106.co.uk/djonair/reqs/devil.png";
}

But before the last else statement which is a catch all in case none of the other options are active. You could simply have your auto dj option in the final "else" statement and use all the other "if" statements for your DJ shows. Basically that's like saying "If this or that dj is onair, show this or that link. Otherwise, show the autodj link."

else
{
  //Does not match either timeframe
  echo "Outside the range of options. Current time is: ".date('g:i A').".";
}

?> 

 

Hope that helps some.

Link to comment
Share on other sites

That is just a comment.

 

In this code:

 

if (date('G') >= 18)
{
  //It is 6pm or later but not past midnight
  echo "http://www.destiny106.co.uk/djonair/reqs/rabbit.png";
}

 

the "if" statement is checking the current time to see if it is after 18:00 (6pm) or equal to that time.

 

the date('G') code simply returns the current hour in 24hour clock format (possible values will be 0 through 23). So it will return 18 starting at 6:00pm through 6:59pm. At 7:00pm you will get 19 and so on.

 

If it is found to be equal to or greater than 18, everything inside the { } will be run. In this case, it will simply display your request image/link. If not, it will skip it and look for an "else" or "else if" statement. That continues through until the end.

Link to comment
Share on other sites

ok think i got it

 

<?php

 

if (date('G') >= 06)

{

//It is 12pm or later but no later than 4:00

echo "

http://www.destiny106.co.uk/djonair/reqs/ultra.png
";

}

else if (date('G') >= 4 && date('G')

{

//It is 6pm or later, but not later than 12:00

echo "

http://destiny106.co.uk/djonair/reqs/devil.png
";

}

else if (date('G') >= 0 && date('G')

{

//It is 12am or later, but not later than 3:59

echo "

http://destiny106.co.uk/djonair/reqs/rabbit.png
";

}

else

{

//Does not match either timeframe

echo "Outside the range of options. Current time is: ".date('g:i A').".";

}

 

 

?>

Link to comment
Share on other sites

You might want to change the comments to match what the functions are actually checking for. I moved the comments to where they might make a little more sense and edited them to show for each of the checks you set, what the functions are actually checking for.

 


if (date('G') >= 06) //It is 6am or later
{
  echo "http://www.destiny106.co.uk/djonair/reqs/ultra.png";
}
else if (date('G') >= 4 && date('G') {
  echo "http://destiny106.co.uk/djonair/reqs/devil.png";
}  
else if (date('G') >= 0 && date('G') {
  echo "http://destiny106.co.uk/djonair/reqs/rabbit.png";
}
else  //Does not match any of the above timeframes
{
  echo "Outside the range of options. Current time is: ".date('g:i A').".";
}


?>                      

 

Remember that the date('G') will always return a value of 0 through 23. That means that:

 

0 = 12am - 12:59am

1 = 1am - 1:59am

...

13 = 1pm - 1:59pm

...

23 = 11pm - 11:59pm

 

There are some conflicting times in your code. Your first "if" statement will always be true if it is later than 6am. I don't think that was what you wanted. Otherwise, your first "else if" statement will only be fired off from 4am until 5:59am and not through 7:59am. For example, if it is 5am now, your first check will return false and move on to the second one. That one returns true since it is after 4 but before 8. BUT, when 6am comes around, the first check is true and will remain true until 12am.

 

If you meant for it to be checking for 6pm and not 6am, that number needs to be 18 and not 06.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...