Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/10/2013, 06:49
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: Consulta sql segun criterios

Código MySQL:
Ver original
  1. SELECT nombre,
  2.              apellidos,
  3.              provincia,
  4.              localidad,
  5.              direccion,
  6.              email,
  7.              telefono,
  8.              nacimiento,
  9.              sexo,
  10.              estudios,
  11.              monthlastjob,
  12.              yearlastjob,
  13.              favorito
  14. FROM curriculums
  15. WHERE provincia='$provincia'
  16.        AND localidad='$localidad'
  17. /// Aqui otras restricciones....

Luego debes construir el texto de la query en función de los datos que tengas....

Código PHP:
Ver original
  1. $Sql="SELECT nombre,
  2.             apellidos,
  3.             provincia,
  4.             localidad,
  5.             direccion,
  6.             email,
  7.             telefono,
  8.             nacimiento,
  9.             sexo,
  10.             estudios,
  11.             monthlastjob,
  12.             yearlastjob,
  13.             favorito
  14. FROM curriculums ";
  15.  
  16. $filtro="";
  17.  
  18. if(isset($_POST['provincia'])){
  19.      if($filtro=="") $filtro="WHERE ";
  20.      $filtro.="provincia='".$_POST['provincia']."'";
  21. }
  22. if(isset($_POST['localidad'])){
  23.      if($filtro=="") {
  24.            $filtro="WHERE ";
  25.      }else{
  26.            $filtro=" AND ";
  27.      }
  28.      $filtro.="localidad='".$_POST['localidad']."'";
  29. }
  30. if(isset($_POST['nacimiento'])){
  31.      if($filtro=="") {
  32.            $filtro="WHERE ";
  33.      }else{
  34.            $filtro=" AND ";
  35.      }
  36.      $filtro.="nacimiento='".$_POST['nacimiento']."'";
  37. }
  38. if(isset($_POST['sexo']) && $_POST['sexo']!="indiferente"){
  39.      if($filtro=="") {
  40.            $filtro="WHERE ";
  41.      }else{
  42.            $filtro=" AND ";
  43.      }
  44.      $filtro.="sexo='".$_POST['sexo']."'";
  45. }
  46. if(isset($_POST['estudios']) && $_POST['estudios']!="indiferente"){
  47.      if($filtro=="") {
  48.            $filtro="WHERE ";
  49.      }else{
  50.            $filtro=" AND ";
  51.      }
  52.      $filtro.="estudios='".$_POST['estudios']."'";
  53. }
  54. if(isset($_POST['monthlastjob'])){
  55.      if($filtro=="") {
  56.            $filtro="WHERE ";
  57.      }else{
  58.            $filtro=" AND ";
  59.      }
  60.      $filtro.="monthlastjob='".$_POST['monthlastjob']."'";
  61. }
  62. if(isset($_POST['yearlastjob'])){
  63.      if($filtro=="") {
  64.            $filtro="WHERE ";
  65.      }else{
  66.            $filtro=" AND ";
  67.      }
  68.      $filtro.="yearlastjob='".$_POST['yearlastjob']."'";
  69. }
  70.  
  71. $Sql.=$filtro;
  72.  
  73. echo $Sql."<br />";//Solo sirve de control para ver que se ha construido.
  74.  
  75. //EXTRAER LOS RESULTADOS DATOS
  76. $consulta=mysql_query($Sql)OR DIE("No se pudo realizar la consulta");
  77. ...

Ojo entre indiferente y nada en estudios.....
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.