Automatic Daily Update

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Superman859
Forum Commoner
Posts: 47
Joined: Sun Oct 29, 2006 10:22 am

Automatic Daily Update

Post by Superman859 »

I'm about to make a script that automatically updates a 'word of the day' section for a foreign language website.

I know how to create a MySQL database to store all of the words, and have a position laid out on the website in which the words will be displayed. However, I'm unsure of how to have it automatically update the word each day.

Is there a SQL command or PHP command that will automatically retrieve the next row in a database each day? I aim to use keys along the lines of 'word_id' or something, which would simply start at 1 (or 0) and continue up from there.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

No. To get an integer ID from the day, try this function:

Code: Select all

function getDateID($num_rows) {
  return floor(time() / 86400) % ($num_rows - 1);
}
Explanation:
- floor(time() / 86400) returns the number of days since the Unix epoch by dividing the number of seconds since the Unix epoch, dividing it by the number of seconds in a day, and then rounding down.
- " % $num_rows returns the remainder of the number of days since the Unix epoch divided by the number of rows you can serve. This would be, presumably, the ID you seek.

Notes:
- Untested
- Ids most start from zero and be continuous
User avatar
churt
Forum Commoner
Posts: 39
Joined: Wed Oct 04, 2006 9:59 am

Set start date

Post by churt »

Set a start date and then take the difference between that date and the current to pull the id you want.

Code: Select all

$dy=strtotime('2006-11-17')-strtotime('2006-11-14');
echo date('j', $dy);
Superman859
Forum Commoner
Posts: 47
Joined: Sun Oct 29, 2006 10:22 am

Post by Superman859 »

Thanks for the ideas.

I also found one that will work for my case, it'll go back to beginning every year..

Just use the date('z') function. Returnes 0-365, day of the year. Or date('j') for month 0-31.

I just need to get enough entries put in to make it work now, or work around with it a little bit.
Post Reply