Good I have this query but it does not return anything to me, only it returns to me when all the data are complete, if only I put a city does not return nothing try to thunder the query but even so it does not return anything, as q does not enter any advice?
Model
$and1 = '';
$and2 = '';
$and3 = '';
$and4 = '';
$and5 = '';
$month1 = date('m');
$year1 = date('Y');
$fecha3 = date('Y-m-d', mktime(0,0,0, $month1, 1, $year1));
$month2 = date('m');
$year2 = date('Y');
$day2 = date("d", mktime(0,0,0, $month2+1, 0, $year2));
$fecha4 = date('Y-m-d', mktime(0,0,0, $month2, $day2, $year2));
if($fecha == '' and $fecha2 == ''){$and3 = 'AND val.val_id_asessor = '.$asesor.'';}
elseif ($fecha2 == '' && $asesor == '') {$and1 = 'AND val.val_fecha_registro >= "'.$fecha.'"';}
elseif ($asesor == '') {$and2 = 'AND val.val_fecha_registro between "'.$fecha.'" and "'.$fecha2.'"';}
elseif ($asesor == '' && $fecha == '') {$and4 = 'AND val.val_fecha_registro >= "'.$fecha2.'"';}
elseif($fecha2 == ''){$and5 = 'AND val.val_fecha_registro >= "'.$fecha.'" AND val.val_id_asessor = "'.$asesor.'"';}
elseif($ciudad == 'Todos' && $asessor == '' && $fecha == '' && $fecha2 == ''){
$qry = 'SELECT val.idval_valuaciones AS id,
val.val_fecha_registro AS fecha_registro,
val.val_nom_contacto AS contacto_nombre,
val.val_modelo AS modelo,
val.val_aps AS aps,
val.val_id_asessor AS ase,
val.val_ciudad AS ciudad,
CONCAT( u.hus_nombre, " ", u.hus_apellido ) AS asessor
FROM valuaciones_seminuevos AS val
LEFT JOIN huser u ON u.hus_IDhuser = val.val_id_asessor
WHERE val.val_fecha_registro between "'.$fecha3.'" and "'.$fecha4.'"';
return $this->db->query($qry)->result();
}elseif ($ciudad == 'Ti' || $ciudad == 'Me' || $ciudad == 'Af' && $asesor == '' && $fecha == '' && $fecha2 == '') {
$qry = 'SELECT val.idval_valuaciones AS id,
val.val_fecha_registro AS fecha_registro,
val.val_nom_contacto AS contacto_nombre,
val.val_modelo AS modelo,
val.val_aps AS aps,
val.val_id_asessor AS ase,
val.val_ciudad AS ciudad,
CONCAT( u.hus_nombre,"", u.hus_apellido ) AS asessor
FROM valuaciones_seminuevos AS val
LEFT JOIN huser u ON u.hus_IDhuser = val.val_id_asessor
WHERE val.val_fecha_registro between "'.$fecha3.'" and "'.$fecha4.'"
AND val.val_ciudad = "'.$ciudad.'"';
return $this->db->query($qry)->result();
}elseif($asesor == '' && $fecha == '' && $fecha2 == ''){
$qry = 'SELECT val.idval_valuaciones AS id,
val.val_fecha_registro AS fecha_registro,
val.val_nom_contacto AS contacto_nombre,
val.val_modelo AS modelo,
val.val_aps AS aps,
val.val_id_asessor AS ase,
val.val_ciudad AS ciudad,
CONCAT( u.hus_nombre," ", u.hus_apellido ) AS asessor
FROM valuaciones_seminuevos AS val
LEFT JOIN huser u ON u.hus_IDhuser = val.val_id_asessor
WHERE val.val_ciudad = "'.$ciudad.'"
AND val.val_id_asessor = "'.$asesor.'"
AND val.val_fecha_registro between "'.$fecha.'"and "'.$fecha2.'"';
return $this->db->query($qry)->result();
}else{
$qry = 'SELECT val.idval_valuaciones AS id,
val.val_fecha_registro AS fecha_registro,
val.val_nom_contacto AS contacto_nombre,
val.val_modelo AS modelo,
val.val_aps AS aps,
val.val_id_asessor AS ase,
val.val_ciudad AS ciudad,
CONCAT( u.hus_nombre,"", u.hus_apellido ) AS asessor
FROM valuaciones_seminuevos AS val
LEFT JOIN huser u ON u.hus_IDhuser = val.val_id_asessor
WHERE val.val_ciudad = "'.$ciudad.'"
'.$and1.'
'.$and2.'
'.$and3.'
'.$and4.'
'.$and5.'';
return $this->db->query($qry)->result();}
Controller, loq only brand is
"Status" => false,
"Message" => "GET"
$ciudad = $_POST['ciudad'];
$asesor = $_POST['asesor'];
$fecha = $_POST['fecha'];
$fecha2 = $_POST['fecha2'];
$data = $this->valuaciones->busqueda_valuaciones($ciudad,$fecha,$fecha2,$asesor);
if ($data) {
$this->output
->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode(array(
"Status" => true,
"Message" => "GET",
"Data" => $data
)));
}else
{
$this->output
->set_content_type('application/json')
->set_status_header(500)
->set_output(json_encode(array(
"Status" => false,
"Message" => "GET"
)));
}