Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cron? Timed events with PHP/SQL

    Hi guys. Read alot of threads here but havn't posted till now.

    Im developing a little site just to give me something to do and experiment with, basically I have everything down with using php to add/edit/remove stuff from mySQL tables and user logins with sessions etc.

    Its basically a mini ebay style that will never be used by anyone its just for me to practice development, basically a user can add an item, browse other peoples items etc etc. All the basic stuff

    The next step I want to do is make the entrys (items) that people add to the database only last a week before being removed and needing to be relisted, the other option I need it for is for the item to be able to be "bidded on" which should be easy enough, and just need it to close bids being available after the set time limit, say 7 days again.

    I havn't used Cron jobs before but if I had to guess im assuming I need a host that supports them? (hoping my current host does) or are there other options available.

    Im by no means "advanced" or a programmer so im just looking for the easiest solution that works to get me started, if anyone could help out or least point me in the right direction for reading it would be appreciated it.

    Thanks in advance

  • #2
    Regular Coder
    Join Date
    Jan 2011
    Posts
    120
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Make a date field and set them as now().

    PHP script that runs query to delete rows where current date is >7 days past the items date field.

    You can run the PHP script as a cron job.

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    for the inactive posting thing..

    if u have a date_posted field, use unix timestamp time();

    then in your php script do something like..

    PHP Code:
    $query mysql_query("select posting_id FROM postings WHERE date_posted > 604800"); // 7 days
    while($f  mysql_fetch_array($query))
    $id $f[0];
    {
    mysql_query("DELETE FROM postings WHERE posting_id = '$id'");

    then you can set up a cron job where it will run that every 7 days


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •