I have a series of queries which all depend on the period 'FY' and in turn quarter 'Q'. What I want to do is use two selections and when the user selects the period and quarter that he wants to see, he changes the results collected from the database. At the moment I have all this.
date_default_timezone_set("America/El_Salvador");
//para la fecha actual
$hoy = date('Y-m-d');
//esta consulta es para saber en que periodo esta la fecha actual
$consultaPeriodo = "SELECT p.fecha_inicio, p.fecha_fin, p.idperiodo, p.nombre_periodo FROM periodo p WHERE '$hoy' BETWEEN p.fecha_inicio AND p.fecha_fin";
$resultadoPeriodo=mysqli_query($conexion_mysql,$consultaPeriodo) or die ("Error");
//como no recorre por completo la tabla periodo, lo hare asi. dado que solo necesito valores unicos de la consulta
$fila = $resultadoPeriodo->fetch_array();
$id_periodo = $fila["idperiodo"];//obtendre del id del periodo
$nombre_periodo = $fila["nombre_periodo"];//obtendre el nombre del periodo
$inicio_periodo = $fila["fecha_inicio"];//obtendre el inicio del periodo
$fin_periodo = $fila["fecha_fin"];//obtendre el fin del periodo
$trimestre_nombre = "";
//calculando el trimestre, el numero de trimestre del anio
$mes = date("m",strtotime($hoy));
$mes = is_null($mes) ? date('m') : $mes;
$trim=floor(($mes-1) / 3)+1;
// echo "trimestre: ".$trim;
if ($trim == 1)
{
//$trimestre_nombre = "Q-3";
$trimestre_nombre = "Q-2";
}
else if ($trim == 2)
{
$trimestre_nombre = "Q-3";
}
else if ($trim == 3)
{
$trimestre_nombre = "Q-4";
}
else if ($trim == 4)
{
$trimestre_nombre = "Q-1";
}
<div class="row">
Select period (FY): Select quarter: Quarter 1 Quarter 2 Quarter 3 Quarter 4 id period Period name Start date End date
</h3>
</div><br>
<div class="row" id="records">
<div class="col-sm-4" id="id_periodo"></div>
<div class="col-sm-4" id="nombre_periodo"></div>
<div class="col-sm-4" id="fecha_inicio"></div>
<div class="col-sm-4" id="fecha_fin"></div>
</div>
<div class="row" id="no_records"><div class="col-sm-4">Por favor seleecione el FY</div></div>
</div>
</div>
This executes a .js file
$(document).ready(function(){
// code to get all records from table via select box
$("#fy_select").change(function() {
var idperiodo = $(this).find(":selected").val();
var dataString = 'idperiodo='+ idperiodo;
$.ajax({
url: 'opc_menu/listarFY.php',
dataType: "json",
data: dataString,
cache: false,
success: function(fy_rrhh) {
if(fy_rrhh) {
$("#heading").show();
$("#no_records").hide();
$("#id_periodo").text(fy_rrhh.id_periodo);
$("#nombre_periodo").text(fy_rrhh.nombre_periodo);
$("#fecha_inicio").text(fy_rrhh.fecha_inicio);
$("#fecha_fin").text(fy_rrhh.fecha_fin);
$("#records").show();
} else {
$("#heading").hide();
$("#records").hide();
$("#no_records").show();
}
}
});
})
});
And there are the queries in which I would like the value to change according to what the user selects.
$respuesta_OC =0;
$respuesta_OC2 = 0;
$totalOC_RRHH = "SELECT respuesta FROM respuestas INNER JOIN preguntas ON respuestas.id=preguntas.id INNER JOIN oficina ON respuestas.oficina=oficina.identificador WHERE identificador='OCRH' AND periodo='$nombre_periodo' AND trimestre='$trimestre_nombre' AND respuestas.id='RRHH2_ID23'";
if($resultPreguntaOC = mysqli_query($conexion_mysql, $totalOC_RRHH)){
while($fila=mysqli_fetch_object($resultPreguntaOC))
{$respuesta_OC = $fila->respuesta;}//dato de la respuesta segun oficina
}
$totalOC_RRHH2 = "SELECT respuesta FROM respuestas INNER JOIN preguntas ON respuestas.id=preguntas.id INNER JOIN oficina ON respuestas.oficina=oficina.identificador WHERE identificador='OCRH' AND periodo='$nombre_periodo' AND trimestre='$trimestre_nombre' AND respuestas.id='RRHH1_ID27'";
That's all I have in a div charge the value of the FY that is selected but what I need is that it affects all the other variables, but I have not been able to solve that. Thank you very much in advance.