Ver Mensaje Individual
  #7 (permalink)  
Antiguo 08/02/2009, 20:17
Avatar de Triby
Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Problemas con sonsulta SQL con matriz e implode en PHP

Sugiero reemplazar:
Código PHP:
if($cedula="")

$where_cedula "%";
}
if(
$nombre="")

$where_nombre "%";
}
if(
$cargo="")

$where_cargo "%";
}

if(isset(
$cedula) && $cedula!="")
{
$where_cedula " cedula LIKE '%".$cedula."%'";
}
if(isset(
$nombre) && $nombre!="")
{
$where_nombre " nombre LIKE '%".$nombre."%'";
}
if(isset(
$cargo) && $cargo!="")
{
$where_cargo " nombre LIKE '%".$cargo."%'";

Por:
Código PHP:
$where_array  = array();

if(isset(
$cedula) && $cedula!="")
{
$where_array[] = " cedula LIKE '%".$cedula."%'";
}
if(isset(
$nombre) && $nombre!="")
{
$where_array[] = " nombre LIKE '%".$nombre."%'";
}
if(isset(
$cargo) && $cargo!="")
{
$where_array[] = " nombre LIKE '%".$cargo."%'";

Edito: solo falta analizar si hay algun filtro a activar:

Código PHP:
// Si tiene algun filtro, se incluye WHERE y los filtros, de lo contrario, nada
$where = (count($where_array) > 0) ? 'WHERE ' implode(" AND "$where_array) : '';
$query "SELECT * FROM responsable $where ORDER BY cedula"
__________________
- León, Guanajuato
- GV-Foto