Record the start and end date that he entered the category and leave the server scheduled to check if it is between the 10 day period, if it has not passed it it removes the data.
You can schedule a script with crontab on the server as follows, it will ping your script according to the time period you program, and in this script, you check the date:
Will run:
- Once a year:
0 0 1 1 *
.
- Every month:
0 0 1 * *
.
- Once a week:
0 0 * * 0
.
- Once a day:
0 0 * * *
.
- Every hour:
0 * * * *
.
0 0 * * 0 php /path/complete/do/seuscript.php
Your script:
<?php
$mysqli = new mysqli("localhost", "root", "senha", "banco");
/* verifica se está conectado */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "DELETE FROM evento
WHERE status =1
AND now() NOT BETWEEN data_inicial AND data_final";
$stmt = $mysqli->prepare($query);
And to save the 10 day period:
$mysqli = new mysqli("localhost", "root", "senha", "banco");
/* verifica se está conectado */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$nome = $_POST['nome'];
$dataInicial = new DateTime();
$dataFinal = new DateTime('+10 days');
$query = "INSERT INTO evento (nome, categoria, status, data_inicial, data_final) VALUES(?,null, 1, ?, ?) ";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("sss", $nome, $dataInicial, $dataFinal);