/    Sign up×
Community /Pin to ProfileBookmark

What’s the best way of doing this? (Changin a variable once a day)

Hi all, here’s what I’m aiming to do:

I have an XML file, quotes.xml, which contains several quotes from different famous people.

What I want to do is pull in one quote at a time. I’ve no problems doing this – it’s working perfectly with a random quote being pulled into a web page each time.

However, I need the page to ‘cycle’ through the list of quote entries in the XML. I.e., one day it will use the first quote, then after 24 hours it will use the second quote, 24 hours after that it will use the third quote, etc. When it reaches the end it will start from the beginning again.

The method I’ve thought of was in creating a file on the server which stores something like $lastQuote = 6; and somehow checks this every day, changes it to 7 and starts using quote number 7.

This seems like it may be unnecessary though, and surely opening and reading a file every time the page is loaded would use many server resources? Can someone suggest the best way of going about doing this?

Many thanks in advance

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pcthugNov 08.2006 — [code=php]
$num = 30; // number of quotes that exist
$day = date('z'); // the day of the year (starting from 0)
$i = 0; // base integer

while($day > $num)
$day -= $num;

// now retrieve quote number via the day variable
?>
[/code]
Copy linkTweet thisAlerts:
@mjdamatoNov 08.2006 — Here's a very easy, one-line solution:

<i>
</i>$todaysQuote = $quoteList[date("z") % count($quoteList)]
×

Success!

Help @cdk57 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...