stylish stylish - 3 months ago 9
MySQL Question

automaticall updating the records every day

I am using this code

$q = mysql_query("SELECT `time` from `table`");
$row = mysql_fetch_assoc($q);
$timeDiff = time() - $row['time'];
if ($timeDiff >= 86400){
//run code
}


but I am getting an error in in the second line can someone plz help me with this

Answer

Here you go:

$datetime = new DateTime("+1 days");
$date = $datetime->format("Y-m-d H:i:s");

$timeDiff = time() - $row['time'];

if($timeDiff >= '$date) {

 //Code Here

}

Edit:

You can update your code in your_file.php and run this:

0 0 1 * * php /var/www/vhosts/your_somain.com/httpdocs/scripts/your_file.php

This will run once a month, on the first day of the month at midnight (i.e. January 1st 12:00am, February 1st 12:00am etc.):

For further explanation:

Reference: tutsplus.com

Hope it will help you.