Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Auto Pruning An Sql Database With Php, How can i do this?
shadowx
post May 16 2007, 03:03 PM
Post #1


A clever man learns from his own mistakes, a WISE man learns from those of OTHERS
*********

Group: [HOSTED]
Posts: 884
Joined: 12-April 06
From: Essex, UK
Member No.: 21,719



Hey all.

Now i have a DB, an SQL DB, and i need to auto prune the data there to delete rows lder than a certain time, lets say 2 months for now, the question is how do i do this?

The obvious thing is just to add a field which is the numerical representation of the month when the data is entered and every time the DB is accessed it will check this number against the current month,in a numerical format, and if the difference is two or greater that row is deleted, so if the month is January, it would be O1 and if the current month is march then it would be O3 and the difference is 2 so it would be deleted. This sounds fine untill you take into account how months work... it goes from 1-12 then back to one again! i guess i can overcome that but it seems complicated.

Now im thinking perhaps SQL has a built in way of comparing dates? if so what is it?!

I could simply delete any entries after a certain number of rows but if this website becomes popular then this number of rows might be exceeded in a few days or less so even recent entries would be deleted.

Any ideas?

Thanks
Go to the top of the page
 
+Quote Post
ghostrider
post May 16 2007, 10:41 PM
Post #2


Super Member
*********

Group: Members
Posts: 397
Joined: 9-June 06
From: Wisconsin
Member No.: 24,924



Use your idea of adding a field with the month, but just keep incrementing the months as the years go by. For example, January would be one (or whatever month you choose to start on), Februrary would be two, but January of next year would 13. Its not as hard as it sounds. You can find out what month it is based on this equation.

Let y = year you started
Let m = current month
Let z = current year

12(z - y) + m

Does this help?
Go to the top of the page
 
+Quote Post
shadowx
post May 17 2007, 07:14 AM
Post #3


A clever man learns from his own mistakes, a WISE man learns from those of OTHERS
*********

Group: [HOSTED]
Posts: 884
Joined: 12-April 06
From: Essex, UK
Member No.: 21,719



Ah yes, that makes sense, so long as i use the year as a four digit number, not a 2 digit because every change of the decade would screw it up!

thanks for that, i shall try that when i get in from college later, it would be interesting to know how Microsoft Access, the DB application, does this because yu can compare dates directly in that and as far as i know it is just a front end application for an SQL database, though i might be wrong.
Go to the top of the page
 
+Quote Post
slushpuppy
post May 18 2007, 05:20 AM
Post #4


Newbie [Level 2]
**

Group: Members
Posts: 29
Joined: 7-September 06
Member No.: 29,569



Apologies, I didn't realise that the question has already been answered.

This post has been edited by slushpuppy: May 18 2007, 05:22 AM
Go to the top of the page
 
+Quote Post
shadowx
post May 18 2007, 08:06 AM
Post #5


A clever man learns from his own mistakes, a WISE man learns from those of OTHERS
*********

Group: [HOSTED]
Posts: 884
Joined: 12-April 06
From: Essex, UK
Member No.: 21,719



Thats ok if you have a different solution then id be interested to hear it, at the moment ive got ghostrider's solution in the works but im still interested at different angles to approaching the problem for future reference, and it might help someone else out too smile.gif


By the way Ghostrider, thanks, it seems to be working which is good!
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Chatbox / Guestbook(2)
  2. Mysql Edit(4)
  3. Writing To Database Problem With Mysql - Not Writing Forum Post(3)
  4. Help Importing Mysql Database Results(3)
  5. Personal Blog(4)
  6. Script That Deletes A Row In A Mysql Database Usin(1)
  7. Can Reset The Id Auto Increment?(10)
  8. Database Extraction Layer(1)
  9. Is Doing The Whole Database / Php Thing Worth It?(13)
  10. Can You Add Images Into A Mysql Database?(20)
  11. Login / Authetication System Using Database(4)
  12. Suppressing Mysql Error In Php(4)
  13. Crontab Automated Database Backup(2)
  14. Requesting Auto Generating Id Tag In Php Code(2)
  15. Showing Numbers Of Mysql Entries In A Database Table(7)
  1. Code To Install Mysql Database Table?(5)
  2. File In Database(1)
  3. Problem To Join Tables In Database(3)
  4. Php Search Engine Script For Mysql Database(11)
  5. Importing .csv Into Mysql Database(6)
  6. Editing Information In A Mysql Database And Deleting Rows(5)
  7. Download Database Backup(0)
  8. Read Xml And Import Into Database(2)
  9. Can Database Column Names Start With A Number?(1)
  10. Connecting Php Site To Database(6)
  11. Delete Problem With Id(4)
  12. How Do I Connect To Live Database With Php Script?(6)
  13. Ms-access Database Question(3)


 



- Lo-Fi Version Time is now: 26th July 2008 - 01:49 PM