I'm new here, and as the title says the foreach behaves abnormally. I want to list all the driver's schedules per shift (1 = day, 2 = night), in turn these with the days from Monday to Friday (0 = Sunday, 1 = Monday, etc) Bearing in mind that driver 1 has only scheduled turn 2 from Monday to Friday
Here is my table: TBL_CONDUCTOR_HORARIO
id dia turno fecha_reg conductor_id 1 0 2 2017-12-11 1 2 2 2 2017-12-11 1 3 4 2 2017-12-11 1 4 6 2 2017-12-11 1 5 1 2 2017-12-11 1 6 3 2 2017-12-11 1 7 5 2 2017-12-11 1
Here my code:
$turnos[] = (object)['id'=>TURNO_DIA,'title'=>'Día'];
$turnos[] = (object)['id'=>TURNO_NOCHE,'title'=>'Noche'];
$dias = [ (object)['id'=>'0', 'name'=>'Domingo'], (object)['id'=>'1', 'name'=>'Lunes'], (object)['id'=>'2', 'name'=>'Mártes'], (object)['id'=>'3', 'name'=>'Miércoles'], (object)['id'=>'4', 'name'=>'Jueves'], (object)['id'=>'5', 'name'=>'Viernes'], (object)['id'=>'6', 'name'=>'Sábado'] ];
foreach($turnos as $c=>$turno)
{
foreach($dias as $dia)
{
$rsHorarioTurno = (new Select())
->from(array('tu'=>TBL_CONDUCTOR_HORARIO))
->where('tu.condh_conductor_cond_id = ?', $idConductor)
->where('tu.condh_dia = ?', $dia->id)
->where('tu.condh_turno = ?', $turno->id)
->fetchRow();
if($rsHorarioTurno)
{
$dia->checked = "checked";
}else{
$dia->checked = "";
}
}
$turno->dias = $dias;
}
var_dump($turnos);
Here is the problem, the days that add that if they are marked or not, they always come out the same, either turn 1 or turn 2.
And so it prints me:
array(2) { [0]=> object(stdClass)#34 (3) { ["id"]=> int(1) ["title"]=> string(4) "Día" ["dias"]=> array(7) { [0]=> object(stdClass)#26 (3) { ["id"]=> string(1) "0" ["name"]=> string(7) "Domingo" ["checked"]=> string(7) "checked" } [1]=> object(stdClass)#27 (3) { ["id"]=> string(1) "1" ["name"]=> string(5) "Lunes" ["checked"]=> string(7) "checked" } [2]=> object(stdClass)#29 (3) { ["id"]=> string(1) "2" ["name"]=> string(7) "Mártes" ["checked"]=> string(7) "checked" } [3]=> object(stdClass)#30 (3) { ["id"]=> string(1) "3" ["name"]=> string(10) "Miércoles" ["checked"]=> string(7) "checked" } [4]=> object(stdClass)#31 (3) { ["id"]=> string(1) "4" ["name"]=> string(6) "Jueves" ["checked"]=> string(7) "checked" } [5]=> object(stdClass)#32 (3) { ["id"]=> string(1) "5" ["name"]=> string(7) "Viernes" ["checked"]=> string(7) "checked" } [6]=> object(stdClass)#33 (3) { ["id"]=> string(1) "6" ["name"]=> string(7) "Sábado" ["checked"]=> string(7) "checked" } } } [1]=> object(stdClass)#35 (3) { ["id"]=> int(2) ["title"]=> string(5) "Noche" ["dias"]=> array(7) { [0]=> object(stdClass)#26 (3) { ["id"]=> string(1) "0" ["name"]=> string(7) "Domingo" ["checked"]=> string(7) "checked" } [1]=> object(stdClass)#27 (3) { ["id"]=> string(1) "1" ["name"]=> string(5) "Lunes" ["checked"]=> string(7) "checked" } [2]=> object(stdClass)#29 (3) { ["id"]=> string(1) "2" ["name"]=> string(7) "Mártes" ["checked"]=> string(7) "checked" } [3]=> object(stdClass)#30 (3) { ["id"]=> string(1) "3" ["name"]=> string(10) "Miércoles" ["checked"]=> string(7) "checked" } [4]=> object(stdClass)#31 (3) { ["id"]=> string(1) "4" ["name"]=> string(6) "Jueves" ["checked"]=> string(7) "checked" } [5]=> object(stdClass)#32 (3) { ["id"]=> string(1) "5" ["name"]=> string(7) "Viernes" ["checked"]=> string(7) "checked" } [6]=> object(stdClass)#33 (3) { ["id"]=> string(1) "6" ["name"]=> string(7) "Sábado" ["checked"]=> string(7) "checked" } } } }
As you can see in both are equal. Thanks for the help in advance.