Schedule grid with PHP

0

I'm having a little problem with my code, which generates schedules, it is not entering the last time.

Type 07:00 to 10:00 30 min interval but he only goes until 9:30 am he does not record 10:00

This is my code:

<?
date_default_timezone_set("Brazil/East");
$con=@mysql_connect("localhost","root","");
$bd=mysql_select_db("test",$con);
//$hora_inicio = $_POST['hora_inicio'];  
//$hora_final = $_POST['hora_final'];
$hora_inicio = "07:00";  
$hora_final = "10:00";             
$ini = strtotime($hora_inicio);
$fim = strtotime($hora_final);
$atu = $ini;
$i = 1;
for ($atu = $ini ;  $atu < $fim; $atu = strtotime('+30 minutes', $atu)) {
$hr_agendamento = date('H:i', $atu);
$sql = mysql_query("INSERT INTO agenda (id_agenda,hr_agendamento) VALUES('','$hr_agendamento')");                        
}
echo"agenda criada";
?>
    
asked by anonymous 21.08.2017 / 06:48

1 answer

0

This is happening because you are comparing in your for on your line 13 , if $atu is less than $fim .

  

for = $ ini; $ $ end; $ act = strtotime ('+ 30 minutes', $ at))

In order for it to do what you want, you should also compare if $atu is equal to $fim .

  

for ($ atu = $ ini; $

21.08.2017 / 09:18