Page 1 of 1

Automatic Daily Update

Posted: Fri Nov 17, 2006 5:32 pm
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.

Posted: Fri Nov 17, 2006 8:34 pm
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

Set start date

Posted: Fri Nov 17, 2006 9:22 pm
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);

Posted: Sat Nov 18, 2006 12:38 am
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.