/    Sign up×
Community /Pin to ProfileBookmark

Automatic Update

Hello,

I’m going to do my best to describe/explain what I am in need of.

I will be creating/running one of those song-a-day countdowns that singers and bands do online to promote a new album. Unfortunately, I have to be out of town for a few days in the middle of the countdown. I am looking for some kind of script that will automatically change a link every 24 hours to a different link. For example:

Day 1 (00 hours) – link shown on page: [url]www.mydomain.com/song1.htm[/url]
Day 2 (24 hours) – link shown on page is changed to: [url]www.mydomain.com/song2.htm[/url]
Day 3 (48 hours) – link shown on page is changed to: [url]www.mydomain.com/song3.htm[/url]
Day 4 (72 hours) – link shown on page is changed to: [url]www.mydomain.com/song4.htm[/url]

… and so on…

Does anyone know of a script that would do this or could anyone write a script for me that can do this?

Thanks!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobJul 08.2004 — [code=php]
<?PHP
$song = array(6 => "song1.htm", "song2.htm", "song3.htm", "song4.htm");
$d = date('j')-1;
echo("http://www.mydomain.com/" . $song[$d]);
?>
[/code]


This is using the date() function to capture the day of the month and uses an array. The first number of the array should be set to the day before you start the script, and make sure you have enough array values for each day that you need. If need be, you could always use an if() conditional to set to the last song if the day of the month is more that there are array values.
Copy linkTweet thisAlerts:
@jp2004authorJul 08.2004 — Thanks for the reply...

So the 6 is the date or is that the number of hours that it'll wait to change?

And what is the: $d = date('j')-1
Copy linkTweet thisAlerts:
@MstrBobJul 08.2004 — I guess that could have been done differently, unnecessary math.

[code=php]
<?PHP
$song = array(7 => "song1.htm", "song2.htm", "song3.htm", "song4.htm");
echo("http://www.mydomain.com/" . $song[$d]);
?>

[/code]



The '6', which is now '7', is the current day of the month.
Copy linkTweet thisAlerts:
@jp2004authorJul 08.2004 — So, how does it know when to change the link after starting on the 7th? What if the month has 31 and not 30 days?
Copy linkTweet thisAlerts:
@MstrBobJul 08.2004 — The PHP date() function is programmed to know the current day of the month. It nows every bit of information of the date, from the current second to the day of the week. The array is set to start at '7', or whichever day of the month you start the script at, and continues on for each item you add by adding 1. So the script searches the array for the key, and the key being used is the day of the month. This script could obviously be expanded to have 31 sites in the array and each day you would get a song depending on the day of the week. No matter what. On the 23 of December, you get song 23.
Copy linkTweet thisAlerts:
@jp2004authorJul 08.2004 — Alrighty... now, does the code go into my header or where?
Copy linkTweet thisAlerts:
@MstrBobJul 08.2004 — Wherever you have the link for the song, put that inside the href="" attribute, replacing your current value. Make sure the file is name .php instead of .html and you are all set.
×

Success!

Help @jp2004 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...