Ver Mensaje Individual
  #5 (permalink)  
Antiguo 08/11/2013, 13:47
Avatar de Cuervoo
Cuervoo
 
Fecha de Ingreso: octubre-2013
Mensajes: 165
Antigüedad: 10 años, 6 meses
Puntos: 43
Respuesta: Buscador "avanzado"

Porque se están juntando '%alberto%'ANDapaterno, se está juntando todo, me faltó darle espacio cuando agregá algo.

Código PHP:
Ver original
  1. $buscar = 'SELECT * FROM tabla_prueba WHERE ';
  2. $where = '';
  3. if (!empty($nom))
  4. {
  5.     $where .= "nombre LIKE '%$nom%' ";
  6. }
  7. if (!empty($apa))
  8. {
  9.     $where .= (!empty($where)) ? " AND " : '';
  10.     $where .= "apaterno LIKE '%$apa%' ";
  11. }
  12. if (!empty($ama))
  13. {
  14.     $where .= (!empty($where)) ? "AND " : '';
  15.     $where .= "amaterno LIKE '%$apa%' ";
  16. }
  17.  
  18. //Todos if de cada campo
  19.  
  20. $buscar .= $where;
  21. mysql_query($busca) or die("Error en $busca: " . mysql_error());

Asi