Howdie,
I’m trying writing a system that makes predictions about its users based on a test. For part of this I only want the database to store the most recent 500 values.
The current fields I am storing are
ID (Auto increment)
USERID (the users unique ID)
SCORE(an integer)
In an ideal world I would Like the system to drop the oldest row when a unique user gets over 500 records in the database. Is there an easy way to automate this in PHP without making the code really heavy?
You’ll have to store a date/time field so you can determine what’s over 1 month old, then it becomes as simple as:
If you’re not going to have any ‘gaps’ in the auto_incremented ID, you could do a very simple (and very failure prone):
but this would be very unreliable.