Tengo el siguiente codigo que quiero usar para generar todo lo que viene despues del WHERE
Código PHP:
IF($countNvals>0)
{
$nombre = " E.nombre LIKE '%$Nvals[0]%' ";
$appa = " E.Apellido_paterno LIKE '%$Nvals[1]%' ";
$apma = " E.Apellido_materno LIKE '%$Nvals[2]%' ";
$sueldo = " E.sueldo = $Nvals[3] ";
$extra = " PE.cantidad = $Nvals[4] ";
$evento = " REE.pago_evento = $Nvals[5] ";
IF(!empty($cadena[0]))
{
$SueldoTotal .= " WHERE ";
$BonoTaxiTotal .= " NATURAL JOIN empleados E WHERE ";
$PagoExtraTotal .= " NATURAL JOIN empleados E WHERE ";
$sql .= " WHERE ";
IF($Nvals[0])
{
$SueldoTotal .= $nombre;
$BonoTaxiTotal .= $nombre;
$PagoExtraTotal .= $nombre;
$sql .= $nombre;
IF($countNvals>1 AND $Nvals[0]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
IF($Nvals[1])
{
$SueldoTotal .= $appa;
$BonoTaxiTotal .= $appa;
$PagoExtraTotal .= $appa;
$sql .= $appa;
IF($countNvals>1 AND $Nvals[1]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
IF($Nvals[2])
{
$SueldoTotal .= $apma;
$BonoTaxiTotal .= $apma;
$PagoExtraTotal .= $apma;
$sql .= $apma;
IF($countNvals>1 AND $Nvals[2]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
IF($Nvals[3])
{
$SueldoTotal .= $sueldo;
$BonoTaxiTotal .= $sueldo;
$PagoExtraTotal .= $sueldo;
$sql .= $sueldo;
IF($countNvals>1 AND $Nvals[3]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
$i++;
}
IF(($Nvals[0] || $Nvals[1] || $Nvals[2] || $Nvals[3]) && $Nvals[4])
{
$SueldoTotal .= " NATURAL JOIN pagos_extras PE WHERE ";
$BonoTaxiTotal .= " NATURAL JOIN pagos_extras PE NATURAL JOIN contra_empleados E WHERE ";
$PagoExtraTotal .= " NATURAL JOIN pagos_extras PE NATURAL JOIN empleados E WHERE ";
$sql .= " NATURAL JOIN pagos_extras PE WHERE ";
IF($Nvals[0])
{
$SueldoTotal .= $nombre;
$BonoTaxiTotal .= $nombre;
$PagoExtraTotal .= $nombre;
$sql .= $nombre;
IF($countNvals>1 AND $Nvals[0]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
IF($Nvals[1])
{
$SueldoTotal .= $appa;
$BonoTaxiTotal .= $appa;
$PagoExtraTotal .= $appa;
$sql .= $appa;
IF($countNvals>1 AND $Nvals[1]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
IF($Nvals[2])
{
$SueldoTotal .= $apma;
$BonoTaxiTotal .= $apma;
$PagoExtraTotal .= $apma;
$sql .= $apma;
IF($countNvals>1 AND $Nvals[2]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
IF($Nvals[3])
{
$SueldoTotal .= $sueldo;
$BonoTaxiTotal .= $sueldo;
$PagoExtraTotal .= $sueldo;
$sql .= $sueldo;
IF($countNvals>1 AND $Nvals[3]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
IF($Nvals[4])
{
$SueldoTotal .= $extra;
$BonoTaxiTotal .= $extra;
$PagoExtraTotal .= $extra;
$sql .= $extra;
//IF($countNvals>1 AND $Nvals[4]!=$Nvals[max(array_keys($Nvals))])
//$sql .= " AND ";
}
}
IF($Nvals[4])
{
$SueldoTotal .= " NATURAL JOIN contra_pagos_extras PE WHERE".$extra;
$BonoTaxiTotal .= " NATURAL JOIN contra_pagos_extras PE WHERE".$extra;
$PagoExtraTotal .= " WHERE".$extra;
$sql .= " NATURAL JOIN contra_pagos_extras PE WHERE".$extra;
IF($countNvals>1 AND $Nvals[4]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
IF($Nvals[5])
{
$SueldoTotal .= " NATURAL JOIN contra_rel_eventos_empleados REE WHERE ".$evento;
$BonoTaxiTotal .= " WHERE ".$evento;
$PagoExtraTotal .= " NATURAL JOIN contra_rel_eventos_empleados REE WHERE ".$evento;
$sql .= " NATURAL JOIN contra_rel_eventos_empleados REE WHERE ".$evento;
IF($countNvals>1 AND $Nvals[5]!=$Nvals[max(array_keys($Nvals))])
$sql .= " AND ";
}
}
$result = @mysql_query($sql);
Los querys que quiero limitar,
Código PHP:
$SueldoTotal = "SELECT SUM(DISTINCT E.Sueldo) FROM contra_empleados E ";
$BonoTaxiTotal = "SELECT DISTINCT SUM(REE.pago_evento) FROM contra_rel_eventos_empleados REE ";
$PagoExtraTotal = "SELECT DISTINCT SUM(PE.Cantidad) FROM contra_pagos_extras PE ";
$sql = "SELECT DISTINCT E.id_empleado, E.Nombre, E.Apellido_Paterno, E.Apellido_Materno, E.Sueldo FROM contra_empleados E ";
Lo que quiero es definir lo que viene despues del where