Page 1 of 1

[SOLVED] Timed Events

Posted: Mon Jul 31, 2006 5:54 pm
by Neostars
I need help with a script. :D
It needs to change at 12 o'clock every, and change back at 1 o'clock.
Example-
(Before 12):
:o Hello How Are You
(After 12):
:) I'm Fine.

Here's a example in use:
http://www.nhfa.net/
On the right hand panel it says Alerts. Every day at 10, and 4 it changed saying the 'Snowager' is asleep.
I need that exact code they use for my site.

Posted: Mon Jul 31, 2006 8:04 pm
by feyd
here's the places to start: time() and date(), mix a few if's in for flavor and presto, you can do it too. :)

Posted: Tue Aug 01, 2006 8:24 am
by Neostars
Yes, But I don't even have the basic Knowledge of PHP.
This is what I have so far, and it keeps messing up the page saying:

Parse Error
Or
Unexpected '}' on line 99
Or
Parse Error...Blah...T_ELSE on Line 99.

Here's my script:

Code: Select all

<?PHP
$weekDay = date('D'); // Mon - Sun
$hour = date('G');    // 0 - 23
$displayDates = array("Mon", "Tue", "Wed", "Thu", "Fri");
$displayHours = array(6, 14, 22);
if(in_array($weekDay, $displayDates) and in_array($hour, $displayHours))
{"$image = "snowasleep.jpg"}
else{"$image = "snowawake.jpg"}
echo{
"<a href="http://www.neopets.com/winter/snowager.phtml"><img src="http://www.neostars.co.uk/images/layout/new/snowawake.jpg">
Can somebody fix it for me?

Posted: Tue Aug 01, 2006 8:34 am
by JayBird

Code: Select all

<?PHP
$weekDay = date('D'); // Mon - Sun
$hour = date('G');    // 0 - 23
$displayDates = array("Mon", "Tue", "Wed", "Thu", "Fri");
$displayHours = array(6, 14, 22);
if(in_array($weekDay, $displayDates) && in_array($hour, $displayHours))
{
    $image = "snowasleep.jpg";
}
else
{
    $image = "snowawake.jpg";
}
echo '<a href="http://www.neopets.com/winter/snowager.phtml"><img src="http://www.neostars.co.uk/images/layout/new/'.$image.'">';

Posted: Tue Aug 01, 2006 8:39 am
by Neostars
That didn't work.
http://neostars.co.uk/portal2.php

Is there something I have to have enabled on that page to make it work?

Posted: Tue Aug 01, 2006 8:46 am
by JayBird
Post all your code, using the correct tags

Posted: Tue Aug 01, 2006 8:51 am
by Neostars
This is what I have so far. Sorry if I messed up.

Code: Select all

<?PHP
$weekDay = date('D'); // Mon - Sun
$hour = date('G');    // 0 - 23
$displayDates = array("Mon", "Tue", "Wed", "Thu", "Fri");
$displayHours = array(6, 14, 22);
if(in_array($weekDay, $displayDates) && in_array($hour, $displayHours))
{$image="snowasleep.jpg"
else{$image="snowawake.jpg"
echo"<a href="http://www.neopets.com/winter/snowager.phtml"><img src="http://www.neostars.co.uk/images/layout/new/"$image">
But look what it does to the page:
http://neostars.co.uk/portal2.php

Posted: Tue Aug 01, 2006 3:53 pm
by nickvd
Give This a try... please note: you need to end your lines with a semi colon (;) and your logic structures need closing curly braces ala:

Code: Select all

if (something) {
 //do this
} else {
  /do this
}
This code seems to work (all i did was fix the errors you had in yours)

Code: Select all

$weekDay = date('D'); // Mon - Sun
$hour = date('G');    // 0 - 23
$displayDates = array("Mon", "Tue", "Wed", "Thu", "Fri");
$displayHours = array(6, 14, 22);
if(in_array($weekDay, $displayDates) && in_array($hour, $displayHours)) {
   $image="snowasleep.jpg";
} else {
   $image="snowawake.jpg";
}
echo '<a href="http://www.neopets.com/winter/snowager.phtml"><img src="http://www.neostars.co.uk/images/layout/new/'.$image.'">';

Posted: Tue Aug 01, 2006 4:30 pm
by Neostars

Code: Select all

<?PHP
$weekDay = date('D'); // Mon - Sun
$hour = date('G');    // 0 - 23
$displayDates = array("Mon", "Tue", "Wed", "Thu", "Fri");
$displayHours = array(5, 14, 22);
if(in_array($weekDay, $displayDates) && in_array($hour, $displayHours))
{
    $image = "snowasleep.jpg";
}
else
{
    $image = "snowawake.jpg";
}
echo '<a href="http://www.neopets.com/winter/snowager.phtml"><img src="http://www.neostars.co.uk/images/layout/new/'.$image.'"></a>'; 
?>
Everything works EXCEPT the timing. Does it sync with my computer?
Which part effects time? For me I need it to change to the 'snowasleep' at 5 o'clock.
How?

Posted: Tue Aug 01, 2006 4:38 pm
by feyd
date() uses the server's internal time. If you want to adjust the time it references, read up on unix timestamps and the date function at the documentation link provided.

Posted: Wed Aug 02, 2006 9:50 am
by Neostars
This topic can be closed. The code works and I don't need help anymore. Thanks ;)