[SOLVED] Timed Events

Looking for volunteers to join your project? Need help with a script but can't afford to pay? Want to offer your services as a volunteer to build up your portfolio? This is the place for you...

Moderator: General Moderators

Post Reply
Neostars
Forum Newbie
Posts: 6
Joined: Mon Jul 31, 2006 5:37 pm

[SOLVED] Timed Events

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. :)
Neostars
Forum Newbie
Posts: 6
Joined: Mon Jul 31, 2006 5:37 pm

Post 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?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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.'">';
Neostars
Forum Newbie
Posts: 6
Joined: Mon Jul 31, 2006 5:37 pm

Post 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?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Post all your code, using the correct tags
Neostars
Forum Newbie
Posts: 6
Joined: Mon Jul 31, 2006 5:37 pm

Post 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
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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.'">';
Neostars
Forum Newbie
Posts: 6
Joined: Mon Jul 31, 2006 5:37 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Neostars
Forum Newbie
Posts: 6
Joined: Mon Jul 31, 2006 5:37 pm

Post by Neostars »

This topic can be closed. The code works and I don't need help anymore. Thanks ;)
Post Reply