3
I have the following code to release on an agenda days and times available and for that I use the following routine:
//recebo dados do formulario
//inclusive o dia da semana ex.: Friday
$dia_semana = $_POST['dia_semana'];
$hora = $_POST['hora'];
$laboratorio = $_POST['laboratorio'];
$quantidade = $_POST['quantidade']-1;
//pega a data de hoje
//para verificar qual a proxima data correspondente ao
//dia enviado pelo formulario
// como por exemplo, proxima sexta(Friday)
$hoje = date('Y-m-d');
$dia = date("Y-m-d", strtotime("$hoje next $dia_semana"));
$dados = array(
'data' => $dia,
'hora' => $hora,
'laboratorio' => $laboratorio
);
//cadastra no banco a primeira data usando minha funcao
$cadastrar = DBCreate('nw_vip',$dados);
//faz um loop para cadastrar as proximas datas
//com o dia escolhido limitado a quantidade
//passada pelo formulario
for($i=0;$i<$quantidade;$i++)
{
//se a primeira sexta caiu no dia 10
//caucula as proximas somando 7 dias e cadastrando
$dia = date("Y-m-d", strtotime("$dia +7 day"));
$dados = array(
'data' => $dia,
'hora' => $hora,
'laboratorio' => $laboratorio
);
//cadastra no banco usando e minha função
$cadastrar = DBCreate('nw_vip',$dados);
}
My problem if I launch 5 Fridays today and then launch another 5 Fridays, it will repeat the dates.
Then I would need that the second time I was going to release it could consider the last Friday already registered in case there are any and register from it.
Example: I throw 3 Fridays at 8hs:
Sex 24/06 8:00
Sex 01/07 8:00
Sex 08/07 8:00
If later I release again 5 more next day continued from Friday day 15/08. How to make an inquiry to know the date of the last Friday already registered, as my example. Of course it could be another day and even another time.
The MAX function in this context returns me the 'highest' date, in the case that is farthest in the future?
– Rafael Silva
The function returns you the longest date you find in the database table, for the constraints you set in the query. Including future dates already recorded in the table.
– Emerson JS