Function of PHP to buy data against a table created with a FOR

0

I have a table in html of turns that is dynamically created with a FOR having as limiting the schedules that the doctors work and I need to create a SELECT in a modal with the available schedules but I can not find the way to compare the schedules that already have shifts (that I get from a query) with those that are generated by the FOR. I thought I would get it with an if and then pass it through a function to jquery and fill in the SELECT with an .html ()

  $option = mysql_query("SELECT DATE_FORMAT(turnos.dia,'%H:%i') as dia FROM turnos WHERE dia LIKE '".$strFecha."%' AND medico='".$medID."' ORDER BY dia ");

for ($a=$horaDesde;$a<=$horaHasta;$a++) { /*en que horarios trabajan traidos de una tabla sql*/

  foreach ($option as $key => $value) {

    if ($value['dia']!==$a.":00") {"<option>".$a.":00</option>";}
    if ($value['dia']!==$a.":15") {"<option>".$a.":15</option>";}
    if ($value['dia']!==$a.":30") {"<option>".$a.":30</option>";}
    if ($value['dia']!==$a.":00") {"<option>".$a.":45</option>";}
  } 

If I do this, compare each shift schedule with the entire table one by one

    
asked by Joaquinlio 20.09.2018 в 21:30
source

1 answer

0

I found the solution by probing with the array_diff ()

 $option = mysql_query("SELECT DATE_FORMAT(turnos.dia,'%H:%i') as dia FROM 
 turnos WHERE dia LIKE '".$strFecha."%' AND medico='".$medID."' ORDER BY dia 
 ");
 for ($a=$horaDesde;$a<=$horaHasta;$a++) {
 $select[]= $a.':00';
$select[]=$a.':15';
$select[]=$a.':30';
$select[]=$a.':45';  
} 
foreach($option as $value){
$turnos[]=$value['dia'];
}

$resultado = array_diff($select, $turnos);
$horariosDisponibles = NULL;
foreach ($resultado as $key => $value) {
$horariosDisponibles .= '<option>'.$value.'</option>';
}
return $horariosDisponibles;
}
    
answered by 26.09.2018 / 16:32
source