473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

delete expired queries

I had queries stored in mysql database according to queries
publication date (in format 2007-5-6, 2007-4-30 etc.). However, i
would like to implement automatic expired queries deletion after 6
months. For instance, 2007-4-30 released bulletin will be deleted
after it expired 6 months later. How do I peform this?

May 6 '07 #1
2 2173
>I had queries stored in mysql database according to queries
>publication date (in format 2007-5-6, 2007-4-30 etc.). However, i
would like to implement automatic expired queries deletion after 6
months. For instance, 2007-4-30 released bulletin will be deleted
after it expired 6 months later. How do I peform this?
DELETE FROM publications WHERE pubdate < subdate(now(), INTERVAL 6 MONTH);

This presumes that pubdate is a DATE or DATETIME column, or can be
converted to one (say, with strtotime()).

Run this query using the mysql command-line utility from cron or some
regularly scheduled job, daily or weekly or whatever.

May 6 '07 #2
I'm extracting web data from dynamically generated RSS. So, my coding
generally looks like this:

<?php
$datetime = date("Y-n-j");

//check desired information bla bla

$qry = "INSERT INTO `bul_data` (`DATE`, `TITLE`,
`DEPARTMENT`,`CAMPUS`, `LINK`) VALUES (DATE_ADD('$datetime', INTERVAL
1 DAY),'$title','$category','', '$link')";

//auto update queries
$qry1 = "UPDATE `bul_data` SET DATE=DATE_ADD('$datetime', INTERVAL 1
DAY), TITLE='$title', DEPARTMENT='$category', CAMPUS='',
LINK='$link'";
//auto delete expired queries
$qry2 = "DELETE FROM `bul_data` WHERE `DATE` LIKE '{$title_date}' >
SUBDATE('$datetime', INTERVAL 1 DAY)";
$res = mysql_query($qry) OR die(mysql_error());

mysql_query($qry);

echo "New bulletin have been stored.";

mysql_query($qry1);

echo "Records have been updated.";

mysql_query($qry2);

echo "Expired bulletin have been deleted.";
?>

However, it doesn't work to insert desired information into my
database. It works only if I omit the DATE_ADD() function and replace
it with '$datetime'.

May 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rahul Chatterjee | last post by:
Hello All I have a web pagewhich queries a db and displays information on the subsequent page. On the subsequent page if I click back to previous page (this is a button with javascript code on...
1
by: Danny | last post by:
sorry for posting a question that has probably been posted hundreds of times, but i can't seem to find the answer i need...We're using a Sql Server 7.0 database and recently started getting timeout...
1
by: Resant | last post by:
Hi All, I have a problem with my Server since I've install Terminal Services. Sometimes my users get error 'Timeout expired' when trying to query or open program. Whatshould I do to increase the...
13
by: N. Graves | last post by:
Thanks for take time to read my question!! I'm using code that will automatically delete rows of data in a field and of course when you do this Access will prompt you that you are about to...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
2
by: Chakravarti Mukesh | last post by:
Hi all, I have put some queries on the page that takes too much time to execute. Thus at the time of peak load it gives the following error. Server Error in '/ge' Application....
6
by: manning_news | last post by:
Using A2003. I'm attempting to delete all queries in an mdb. I was experimenting with the following coding and discovered that it deletes exactly half the queries each time it's run. If I have...
17
by: (PeteCresswell) | last post by:
I've got apps where you *really* wouldn't want to delete certain items by accident, but the users just have to have a "Delete" button. My current strategies: Plan A:...
1
by: austin1539 | last post by:
-Access 2002 -Windows XP Pro Trying to run a DELETE Query to delete each entry in the table 'Data' where the field 'AssocID' matches the field 'AssocID' in the table 'Queries' and the date is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.