Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 27th, 2004, 02:50 PM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default automatic record delete.

Can I do a automatic record delete? For example, I would have the possibility to select a "option" that delete record in certain date, in automatic mode.

it is possible? (excuse me for my english..eheh:))

thanks

joeore

Reply With Quote
  #2 (permalink)  
Old April 27th, 2004, 05:56 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't really know what you mean. Can you be more descriptive? I don't know what you mean by "automatic mode".


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #3 (permalink)  
Old April 27th, 2004, 06:17 PM
Authorized User
 
Join Date: Sep 2003
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello nikolai:), I mean that a record must be deleted when pass a certain time, for example 15 days.

It's possible?

joeore:)

Reply With Quote
  #4 (permalink)  
Old April 28th, 2004, 09:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can't write anything into the record that effectively gives it a "time to live", but depending on how much access you have to the machine you are running on, you could use something like a cron job (aka. a "Scheduled task" on Windows) or a stored procedure running on the database itself (assuming you database manager supports them - recent versions of MySQL, Postgres and SQL Server do, Access doesn't).

Run it at midnight each day to filter off records you no longer want.
Reply With Quote
  #5 (permalink)  
Old April 28th, 2004, 08:23 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right. Your PHP script would look something like this:

<?php // delete_old.php

// connect to db here...

$expired = date("Y-m-d", strtotime("-15 days"));

$query = "DELETE FROM table WHERE date_col < '$expired'";
mysql_query($query);
?>

On the commandline, you would execute this by:

php -q delete_old.php


strtotime() creates a UNIX timestamp based on a string representation. We create the timestamp for 15 days ago. We use date() to format it into YYYY-MM-DD format, which is how MySQL stores items in DATE columns. (DATE is a MySQL data type).

More info:
  http://www.php.net/strtotime
  http://www.php.net/date


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #6 (permalink)  
Old April 29th, 2004, 11:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Or (swiftly dons smart-arse cap, at this point):

date("Y-m-d", strtotime("fortnight 1 day ago"));

A swift guide to the GNU fuzzy-logic relative time functions can be found here.
http://www.gnu.org/software/coreutil...27.html#SEC174

Dan
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete a record row, not just the record. Coby Access VBA 1 April 30th, 2007 06:29 AM
automatic insertion of new record.....help...... abhit_kumar JSP Basics 1 March 4th, 2005 12:50 PM
automatic insertion of new record.....help...... abhit_kumar Pro JSP 0 March 4th, 2005 04:56 AM
Can't delete record Trojan_uk SQL Server 2000 3 November 27th, 2003 01:03 PM
Delete record but how? scifo Beginning PHP 3 August 1st, 2003 12:14 PM



All times are GMT -4. The time now is 02:01 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.