Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    131
    Member #
    13656
    I'm sure there is a way to do this... I am currently working on a site that displays information on a timed sensative basis. Using tables (db tables that is) I want to take the information from one table and after it has expired, move it to an 'expired' table and delete it from the original table. Now I know how to do this manually, but how would I do this on a timed basis? i.e. To happen once or twice a week?

    Let me know! Thanks in advance!
    Christopher Carvache
    Web Developer / SEO
    Northeast Web Design
    +1.860.906.7802

  2.  

  3. #2
    Member Taffu's Avatar
    Join Date
    Dec 2006
    Posts
    34
    Member #
    14486
    I think I know what you're trying to achieve. As an example, I'll use a "Classified" section where people would sell things as an example. Let's say you allow a user to post a classified ad on your site, but you want it to function on an "Expire" basis where their ad is only good for, lets say, 3 days (72 hours).

    First, you would want to add columns to whatever table you're using to handle the date & time (you can use seperate columns, or one, and define them how you want...experiment with what works bes for you). For the sake of this example, I'm setting a datetime single column with default set to "0000-00-00 00:00:00" and having the column timestamp upon alteration (this lets your INSERT session work without having to add functions or change any of your current MySQL query's). What this does is, when someone submits their classified ad, it timestamps the information into your new column at the time of insertion and gives it our starting value to use in what we'll compare in the next two functions.

    What you want to do next, since you now have a start date/time timestamped into your rows of stored data, is create some kind of check function on whatever page outputs these ads for viewing. So if you have a page to view the ads, that uses something like a "SELECT * FROM your_ad_database" and then takes the results and puts them into some sort of listing for viewing, you want your new check function to check the timestamp in your datetime column and compare it to the current time.

    Your next function is up to you. If you actually want to transfer the returned "old" information from your check into another seperate database (or seperate table), use your check function and add an "if", set the parameters (if current_time > datetime + 3 days...defining it as old), use a garbage collection function take your $old data and create a transfer_write function to take the returned data and insert it into your other database. If you're just looking to rid of the data rather than transfer it, you could simply use a DELETE query where id=$old_id.
    Owner - http://www.project-guild.com (in development)

  4. #3
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    However, you don't want it to be run on every view, which would be a waste of resource. What you want is cron. Tutorial here.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Though that requires that you have PHP installed in a user-executable, command-line mode. If you don't have that, you can still hopefully use a cron job in conjuncation with a command-line browser like lynx or links to hit a specific page that'll do the check.

    It bears mentioning that if you're on a Windows server, you won't have cron, and that most site management systems give you some sort of interface to add cron jobs easily.

    At the most basic, yes, you would probably want to do what Taffu said if you can't get cron working. You may even be able to compress all of it into one or two independent queries and thus minimize the resource impact if you want to do it when the page gets hit. This'll be good whether you do it when pages are viewed or if you do it via a cron job. Faster is better :-)

    Cron's your best bet, though :-)

  6. #5
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    of your host is windows based or doesnt allow cron like mine try this http://webcron.org/index.php?&lang=en
    Regards Phil,


  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    That's a nice find, leprechaun13.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:33 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com