Este es el codigo que tengo...
Código PHP:
<form method="GET" name="f1" id="f1">
<div class="col-sm-3 col-md-3">
<div class="form-group">
<select class="selectpicker show-tick form-control" maxoption="1" id="desde" name="desde">
<option value=''>Seleccione...</option>
<?php
$sql_fecha = ("SELECT MONTH(fecha) AS mes, YEAR(fecha) AS ano
FROM asistencia_empleado
GROUP BY MONTH(fecha), YEAR(fecha)
ORDER BY ano,mes ASC");
$res_fecha=$bd->ejecutar($sql_fecha);
while($r_fecha=$bd->obtener_fila($res_fecha)){
?>
<option><?php echo $r_fecha['mes'].'/'.$r_fecha['ano'];} ?></option>
</select>
</div>
</div>
<input type="submit" class="btn btn-success btn-md" id="btn" name="submit" value="Buscar" onclick="f1.action='reporte_asistencia.php'">
</form>
<?php
if(empty($_GET['desde'])){
$desde="";
}
else{
$desde = $_GET['desde'];
}
//Separo el mes y el año para el query de asistencia
$a = explode("/", $desde);
$mes = $a[0];
$año = $a[1];
$fin="";
switch($mes){
case 1:
$fin=31;
break;
case 2:
if ((($año % 4 == 0) && ($año % 100 != 0)) || (($año % 100 == 0) && ($año % 400 == 0))){
$fin=29;
}
else{
$fin=28;
}
break;
case 3:
$fin=31;
break;
case 4:
$fin=30;
break;
case 5:
$fin=31;
break;
case 6:
$fin=30;
break;
case 7:
$fin=31;
break;
case 8:
$fin=31;
break;
case 9:
$fin=30;
break;
case 10:
$fin=31;
break;
case 11:
$fin=30;
break;
case 12:
$fin=31;
break;
}
?>
<div class="row">
<div class="col-sm-2 col-md-8 col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Reporte de Asistencia</h3>
</div>
<div class="table-responsive">
<table class="table table-success">
<thead>
<tr class="">
<th>Cedula</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Turno</th>
<th>Nombre</th>
<th>Apelido</th>
<th>Servicio</th>
<th><?php for ($i=1; $i<=$fin; $i++) { echo $i.'/'.$mes.'/'.$año;?></th>
<th><?php }?></th>
</tr>
</thead>
<?php
$sql = ("SELECT MONTH(asistencia_empleado.fecha) AS Mes, YEAR(asistencia_empleado.fecha) AS Ano, asistencia_empleado.fecha, empleados.nombre,
empleados.apellido, empleados.cedula, personal_administrativo.nombre AS nomsup, personal_administrativo.apellido AS apesup, tipo_asistencia.codigo AS asistencia,
turno.descripcion AS turno, servicio.servicio
FROM servicio LEFT OUTER JOIN
empleados ON servicio.id_servicio = empleados.id_servicio LEFT OUTER JOIN
turno ON empleados.id_turno = turno.id_turno RIGHT OUTER JOIN
asistencia_empleado LEFT OUTER JOIN
tipo_asistencia ON asistencia_empleado.id_tipo_asistencia = tipo_asistencia.id_tipo_asistencia LEFT OUTER JOIN
personal_administrativo ON asistencia_empleado.id_personal_administrativo = personal_administrativo.id_personal_administrativo ON
empleados.cedula = asistencia_empleado.cedula
WHERE (MONTH(asistencia_empleado.fecha) = '$mes') AND (YEAR(asistencia_empleado.fecha) = '$año') AND asistencia_empleado.cedula='26576741'
GROUP BY MONTH(asistencia_empleado.fecha), YEAR(asistencia_empleado.fecha), asistencia_empleado.fecha, empleados.nombre, empleados.apellido, empleados.cedula,
personal_administrativo.nombre, personal_administrativo.apellido, tipo_asistencia.descripcion, turno.descripcion, servicio.servicio
ORDER BY ano DESC, mes DESC");
$res = $bd->ejecutar($sql);
while($r = $bd->obtener_fila($res)){
?>
<tbody>
<tr>
<td><?php echo $r['cedula'];?></td>
<td><?php echo $r['nombre'];?></td>
<td><?php echo $r['apellido'];?></td>
<td><?php echo $r['turno'];?></td>
<td><?php echo $r['nomsup'] ;?></td>
<td><?php echo $r['apesup'];?></td>
<td><?php echo $r['servicio'];?></td>
<td><?php echo $r['asistencia'];?></td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
</div>
</div>
</div>