We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,894 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

displaying different content everyday

I want to make a little code that displays a different string everyday.
for example I have 100 strings. I want that when a user opens my site they'll see one of the strings that day. the next day they'll see another string..and so forth.
so far I thought about putting all the strings in array and give every string a hardcoded date on which it will displayed, and then with a simple if statement the correct string is going to be displayed.
is there any known(better) way to do this?

3
Contributors
7
Replies
42 Minutes
Discussion Span
4 Months Ago
Last Updated
8
Views
arcticM
Junior Poster in Training
85 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

why you not creating database for string u can add it and next day delete all string with one line query and add new string.

arti18
Posting Whiz in Training
206 posts since Dec 2012
Reputation Points: 2
Solved Threads: 25
Skill Endorsements: 0

I don't want to create a DB for this.. it's really something tiny that I want to be done with as little code as possible.
and what I wonder about is not how to save the strings but how to display a different one everyday without hardcoding the dates.
p.s
i want to set the strings once (not change the string everyday) if I set 30 strings, after 30 days I want the loop to repeat itself (so deleting a string each day won't work cause I'll have to insert it again when I'm out of strings).

arcticM
Junior Poster in Training
85 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You'll need to store somewhere (in a file perhaps) which array index is the current one, and increase that daily.

pritaeas
Posting Prodigy
Moderator
9,268 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

how do i update the index only ONCE a day?

arcticM
Junior Poster in Training
85 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

With a scheduled task (cron job).

pritaeas
Posting Prodigy
Moderator
9,268 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

ok, any other suggestions on doing this inside the code itself?.. i see hardcodding the dates is the only option if I want the code to do it and not something like cron job?

arcticM
Junior Poster in Training
85 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

If you store the current date with the index, you can check if it has changed and overwrite it.

pritaeas
Posting Prodigy
Moderator
9,268 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1335 seconds using 2.71MB