473,396 Members | 2,011 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,396 software developers and data experts.

table data question

Hi,

is it possible to put somekind of parameter on a table that when i put data
into the table it automaticly erase the row when a certain time has past??

i know i can use cookies on the client side but i like to create a simelar
effect on the server side.

is this possible???

thanks
Jul 16 '05 #1
4 2160
JKD
Sound like you would want to execute a perl script via cron.
"The Lone Wolf" <jc*************@pandora.be> wrote in message
news:8X******************@afrodite.telenet-ops.be...
Hi,

is it possible to put somekind of parameter on a table that when i put data into the table it automaticly erase the row when a certain time has past??

i know i can use cookies on the client side but i like to create a simelar
effect on the server side.

is this possible???

thanks

Jul 16 '05 #2
"The Lone Wolf" <jc*************@pandora.be> wrote
in message news:<8X******************@afrodite.telenet-ops.be>...

is it possible to put somekind of parameter on a table that
when i put data into the table it automaticly erase the row
when a certain time has past??


You would have to define a trigger for that. Check you database's
documentation to see if it supports triggers. In case you are using
MySQL, it doesn't support triggers.

Cheers,
NC
Jul 16 '05 #3
The Lone Wolf wrote:
is it possible to put somekind of parameter on a table that when i put data
into the table it automaticly erase the row when a certain time has past??


a cron job or a trigger would be preferable, but if you don't have
access to cron on your server and using MySQL that doesn't support
triggers, the common practice is this:

Put a column in your table that holds the date/time when it should
expire, then do a "garbage collection" at the start of each page. If you
have enough hits, you might want to give it only a 5% or 10% probability
of running with "if(11>rand(1,100))". Adjust the probability so that it
gets run often enough, but doesn't impact your server's performance to
much. When it does run have it delete all records whos expiration has
passed.

Jochen

--
/**
* @author Jochen Buennagel <zang at buennagel dot com>
* @see http://www.sourceforge.net/projects/zang
*/

Jul 16 '05 #4
You bet it is but with a little work. I will assume you are on LAMP
server (Linux, Apache, MySQL, PHP) and provide a general framework for
hot to accomplish this task as I do it now for a customized
replication environment for updating a server that communicates with a
wireless client. You can code the rest for your task.

In the database table add a column with a timestamp field in it. In
mysql the first column of this type will automatically be populated
with the current timestamp by default (a nice feature).

Note: I am not responsible for syntax errors.

CREATE TABLE hotspot
( id MEDIUMINT UNSIGNED NOT NULL
AUTO_INCREMENT PRIMARY KEY
, active_flag CHAR(1) NOT NULL DEFAULT 'Y'
, name VARCHAR(75) NOT NULL
, update_date TIMESTAMP
, comments TEXT
, INDEX name_idx (name)
) TYPE=InnoDB;

The insert statement to create the record would look like:

insert into hotspot (name, comments) values ('mytest', 'Nothing worth
mentioning');

Next, write a php script that then connects to the database and all
that. At this point say you want to find all of the records that are
older than a day you would issue the following sql statement

$sql = 'SELECT id FROM hotspot WHERE update_date >
DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)';

$result = mysql_query($sql, $conn);

while ($row = mysql_fetch_object($result)) {

$deleteRecordSet[] = $row->id;

}

foreach ($deleteRecordSet as $row) {

$sql = "delete from hotspot where id = $row->id";

....

}
You can then setup a cron job to run this php script using a command
line tool like curl (which you should install if you system doesn't
have it)

0 4 * * * curl http://localhost:81/deleteHotspots.php >>
/log/deleteexport.log

Hope that helps!

wes bailey

"The Lone Wolf" <jc*************@pandora.be> wrote in message
news:<8X******************@afrodite.telenet-ops.be>...
Hi,

is it possible to put somekind of parameter on a table that when i put data
into the table it automaticly erase the row when a certain time has past??

i know i can use cookies on the client side but i like to create a simelar
effect on the server side.

is this possible???

thanks

Jul 16 '05 #5

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

Similar topics

2
by: A. Wiebenga | last post by:
Hi all! I am currently involved in a project in which I am supposed to write a XSLT-transformation sheet for some XML data. I will outline the situation first: I've got one large XML file...
2
by: Gordowey | last post by:
I have the next question, and i would like to hear what do you think about, and if is there a better solution for "my problem" here is the question, I have a huge table with 60GB of data (image...
13
by: Peter | last post by:
Can anyone tell me how to change the data type of a field in a table created with a make table query? The field is a binary and must be changed to text. alternately does anyone know how to specify...
15
by: kimi | last post by:
I have just started working on a project that is partially complete. It is an application that is using access to store test results. The test results are being stored in two Access 2000 databases....
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
1
by: Greg | last post by:
Hi, I need to implement a table in XBRL. Let's assume I have 2 simple tables to define: TABLE 1 col1 col2 row1 A C row2 B D TABLE 2
1
by: LurfysMa | last post by:
I am working on an electronic flashcard program. Most of the subjects are simple lists of questions and answers. Those seem to be working. Some of the "subjects" have "categories" of questions. ...
4
by: Takeadoe | last post by:
Dear NGs, I recently downloaded and read a bunch of material on normalizing your data and db design. Things aren't crystal clear yet! Part of the problem is that nearly every thing I read...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.