-2

I'm planning on adding destroyable messages to my website. I want users to choose how long the message should be 'alive'. The message should be destroyed a specific time after creation only if the row meets a column value.

The important columns are:

time, destroy

time is stored as DATETIME in the database.

I want a row to be deleted 1 hour after creation only if destroy equals '1'

I'd highly appreciate it if someone could point me in the right direction as I have no clue on how to approach this.

Thanks in advance

I've read about using cron jobs but I failed to do so.

This is what i've tried:

cron.php

<?php
include 'includes/db.php';
mysql_query("DELETE FROM `d_msg_enc` WHERE `mode` = 1 AND `time` > DATE_SUB(NOW() INTERVAL 10 MINUTE)");
?>
Shadow
  • 33,525
  • 10
  • 51
  • 64
H Goodman
  • 1
  • 1
  • Did you tried anything? Because there is multiple way to achive this functionality. – Bhavin Solanki Sep 19 '16 at 08:54
  • I've read about using a cron job but I failed doing so I'll add it in the OP – H Goodman Sep 19 '16 at 08:55
  • 3
    Why not simply use an expiration date and use that to fetch the right records? You could configure a cronjob to cleanup the records that are past their expiration date. – FrankSunnyman Sep 19 '16 at 08:55
  • Can't imagine why I haven't thought about that.. I got it to work now by using a expiration date and a simple cron job. Thanks! – H Goodman Sep 19 '16 at 09:12

1 Answers1

0

You can not command php script to run after 1 hour (or schedule scripts) .. To accomplish this type of scheduling of scripts use CRONS..

Refer this url for more detail: https://stackoverflow.com/a/18737637/4419992

Community
  • 1
  • 1
Touheed Khan
  • 2,149
  • 16
  • 26