Deleting some entries, automatically with new input?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
phpnewbie3
Forum Newbie
Posts: 17
Joined: Sat Sep 20, 2008 10:15 am
Location: NJ, USA

Deleting some entries, automatically with new input?

Post by phpnewbie3 »

Hi,

I have a MySQL database, PHP input (with PHPMyAdmin).

Can someone give me help on what is the code for when I input a new row in a table, then automatically delete the oldest entries (or entry), so for example always just the last 21 entries are kept in the table (plus the newest entry).

I have the first column in the table "timestamp" set on "ON UPDATE CURRENT_TIMESTAMP" attribute.

Thanks!
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Deleting some entries, automatically with new input?

Post by VladSun »

Why do you need that? Please, explain what you are trying to implement in real world.
There are 10 types of people in this world, those who understand binary and those who don't
phpnewbie3
Forum Newbie
Posts: 17
Joined: Sat Sep 20, 2008 10:15 am
Location: NJ, USA

Re: Deleting some entries, automatically with new input?

Post by phpnewbie3 »

VladSun wrote:Why do you need that? Please, explain what you are trying to implement in real world.
I have a site with sports-betting picks.
Different people are submitting daily picks.
I want to have an accessible record of the last 21 days of their inputs plus the newest one.

Right now is that way that before every new input they click a "delete button", which cleans all the previous entries.
So only the very last input is kept in the database.

Example input interface:

http://profitsportspicks.com/test/input.html

And the example final output:

http://profitsportspicks.com/test/picks.php

In this example I do not have a timestamp in the first column, but I have in another test database.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Deleting some entries, automatically with new input?

Post by VladSun »

Do you think that they delete the rows instead of showing the last 21 ones only ;)
There are 10 types of people in this world, those who understand binary and those who don't
phpnewbie3
Forum Newbie
Posts: 17
Joined: Sat Sep 20, 2008 10:15 am
Location: NJ, USA

Re: Deleting some entries, automatically with new input?

Post by phpnewbie3 »

VladSun wrote:Do you think that they delete the rows instead of showing the last 21 ones only ;)
Not because of this.

The newest entry should be seen anyways, but only on the day the picks are valid for.
That is how it is set up right now.
People can access the output pages by using a password and username, because those pages are individually protected, for all the handicappers.

But I want to also keep in the databases the last 21 days of entries, so anyone can look at those with a different output form. I will use search here.
phpnewbie3
Forum Newbie
Posts: 17
Joined: Sat Sep 20, 2008 10:15 am
Location: NJ, USA

Re: Deleting some entries, automatically with new input?

Post by phpnewbie3 »

Nobody with a solution?

:( :( :( :( :( :( :(

I thought this is a fairly simple thing to do for someone who's advanced in PHP...
Oh well... :roll:
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Deleting some entries, automatically with new input?

Post by andyhoneycutt »

just schedule a cron task to delete out entries older than 21 days every morning. i wouldn't leave this up to your end-users.
phpnewbie3
Forum Newbie
Posts: 17
Joined: Sat Sep 20, 2008 10:15 am
Location: NJ, USA

Re: Deleting some entries, automatically with new input?

Post by phpnewbie3 »

.
Post Reply