Jump to content

Updating mysql database once a day


andrewgarn

Recommended Posts

Ok, what I am creating is a website that will track the highscores off a website, then record each day the scores into a mysql table named "date" with a primary key of the current date.

 

I have worked out the way of extracting the highscores to variables, what I need to work out now is how to make the php file retrieve and store the highscores once a day

 

I was thinking of something like creating a "last update" field in a table then:

 

If last update is greater than 24 hours then run highscore script and save highscores into todays date. This could be a few lines on the homepage, which would be ignored if the last update had been today.

 

However this relies on the php page being loaded once a day, is there any way to automate this, or does this seem like a good solution?

 

Can anyone enlighten me as to what the if function would be for checking todays date against the latest update? (to see if it was greater than 24 hours?)

 

Thanks

Link to comment
Share on other sites

Correction:

It doesn't HAVE to be hosted on a free service, you just WANT it to be hosted on a free service because you don't feel like paying. 

 

If you aren't going to pay, then don't expect everything to work nicely.  Or work at all.

Link to comment
Share on other sites

Then make an if statement to pull the last update time from the table, and if more than 24 hours, run the update query. However, it will still require a page to be loaded to even check against the date.

Link to comment
Share on other sites

Then make an if statement to pull the last update time from the table, and if more than 24 hours, run the update query. However, it will still require a page to be loaded to even check against the date.

 

Yeh i figured that thanks.

 

I have found a web hosting service with cron, i'll try and learn that, see if i can work that out :) - http://www.aokhost.com

 

Thanks

 

As an additional question, for the website I wanted the ability to view changes in highscores:

 

today

this week

last week

this month

last month

this year

etc

 

How can I work out the date one week ago, one year ago with PHP from todays date? (and include error control if there is no highscore data a year ago choose the date in database closest with data)

 

the highscore change would then be worked out by today's highscores - highscores a year ago = highscore change

Link to comment
Share on other sites

SELECT * FROM HighScores WHERE Date>=DATE_SUB(DATE_ADD(CURDATE(), INTERVAL -1 DAY), INTERVAL 1 WEEK)  AND Date<CURDATE()

 

That would get the high scores from the last week, starting before the current day. So you don't get the highest scores from today also, just last week.

Link to comment
Share on other sites

SELECT * FROM HighScores WHERE Date>=DATE_SUB(DATE_ADD(CURDATE(), INTERVAL -1 DAY), INTERVAL 1 WEEK)  AND Date<CURDATE()

 

That would get the high scores from the last week, starting before the current day. So you don't get the highest scores from today also, just last week.

 

So that would select the highscore change from a week ago to yesterday?

 

The highscores work by a username, then a set of values for each username, stored in a date table which is:

 

date (primary) username (foreign) highscore1 highscore2 highscore3

 

would this select the change from yesterday to today?

 

SELECT * FROM HighScores WHERE Date>=DATE_SUB(DATE_ADD(CURDATE(), INTERVAL -1 DAY) AND Date<CURDATE()

Link to comment
Share on other sites

ok, slightly confused now.

 

Would it be easier just to locate the date (minusing a week from current date), then retrieve all the values.

 

retrieve the values from todays date

 

then do todays date values - previous values -> echo on screen the change

 

 

Link to comment
Share on other sites

Sorry I think i'm confusing myself.

 

Functions of website:

 

<> Users sign up to the website

<> Each day the php page takes each user, locates their highscores, retrieves them and saves them to the mysql database with todays date. (this will be achieved with a php script + cron)

 

<>Tracking - users can view their highscore progression by looking:

 

change in highscores over:

 

the current week

last week

the current month

last month

the current year

last year

 

This will be expanded into graphs showing highscore progress once i make the tracking work.

 

EDIT: this tutorial explains how to find out the date a week/day ago: http://www.tutorialparadise.com/watchtutorial.php?tid=514

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.