I want to delete the data that expired.
I have two columns:created_time
: That contain a value indicate to time()
function (ex: 1395836716)
.period
:That contain the period of the remain the row in database (ex: 3 or 7 or 15 or 30 per day)
.
I want to create a query to check on all rows in the table to know the rows that expired.
The problem is I don't know how to do that, but I tried.
$twentyFour = 60 * 60 * 24;
mysql_query("DELETE FROM content WHERE created_time + (period * $twentyFour ) > '" . time() . "' ");
But unfortunately, did not work as I expected.
Edit:
This is a result of row
Edit 2
I did it, by using php conditions:
$twentyFour = 60 * 60 * 24;
$query = mysql_query("SELECT * FROM content");
while ($data = mysql_fetch_assoc($query)) {
if ($data['created_time'] + ($data['period'] * $twentyFour) < time()) {
mysql_query("DELETE FROM content WHERE id = $data[id]");
}
}
The previous code works fine as was I want.
the problem is the previous code will occurs more server load.
I want a query to doing as the previous code does without using conditions.