IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

recherche multiple php


Sujet :

PHP & Base de données

  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Décembre 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2011
    Messages : 20
    Par défaut recherche multiple php
    bonjour
    désoler de refaire un énième topique al dessus, mais même en cherchant et en regardant des exemples
    j'ai pas mal de difficulté a réaliser ce formulaire
    donc je cherche a faire un formulaire multicritère ou on choisis une ou plusieurs option ça affiche tout les résultats en fonction de ces options
    le problème ben c'est que j'ai pas mal de champs afficher, et du coup ma méthode fonctionne bien uniquement quand on peut de choses afficher, ,en effet je dois effectuer ma recherche avec 7-8 critère et en afficher plus de 10, donc je sais pas trop quoi utiliser pour en arriver là.
    si vous avez des idées

    code de la recherche :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    <?php require_once('Connections/gali.php');
    ini_set('error_reporting', 'E_ALL ^ E_NOTICE'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }
     
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
     
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
     
    mysql_select_db($database_gali, $gali);
    $query_Recherche = "SELECT * FROM markers";
    $Recherche = mysql_query($query_Recherche, $gali) or die(mysql_error());
    $row_Recherche = mysql_fetch_assoc($Recherche);
    $totalRows_Recherche = mysql_num_rows($Recherche);
    ?>
    <form method="post" action="add.php">
                            <p>
                                    nom du site : <br />
                              <select name="name"  id="name "value="Choisissez">
                                <option value="" selected="selected"></option>
                                <?php
    do {  
    ?>
                                <option value="<?php echo $row_Recherche['name']?>"><?php echo $row_Recherche['name']?></option>
                                <?php
    } while ($row_Recherche = mysql_fetch_assoc($Recherche));
      $rows = mysql_num_rows($Recherche);
      if($rows > 0) {
          mysql_data_seek($Recherche, 0);
    	  $row_Recherche = mysql_fetch_assoc($Recherche);
      }
    ?>
                              </select>
                              <br />lieu: <br />
                                    <select name="address">
                                      <option value="" selected="selected"></option>
                                      <?php
    do {  
    ?>
                                      <option value="<?php echo $row_Recherche['address']?>"><?php echo $row_Recherche['address']?></option>
                                      <?php
    } while ($row_Recherche = mysql_fetch_assoc($Recherche));
      $rows = mysql_num_rows($Recherche);
      if($rows > 0) {
          mysql_data_seek($Recherche, 0);
    	  $row_Recherche = mysql_fetch_assoc($Recherche);
      }
    ?></select>
                  					<br />statut: <br />
                                    <select name="situation">
                                      <option value="" selected="selected"></option>
                                      <?php
    do {  
    ?>
                                      <option value="<?php echo $row_Recherche['situation']?>"><?php echo $row_Recherche['situation']?></option>
                                      <?php
    } while ($row_Recherche = mysql_fetch_assoc($Recherche));
      $rows = mysql_num_rows($Recherche);
      if($rows > 0) {
          mysql_data_seek($Recherche, 0);
    	  $row_Recherche = mysql_fetch_assoc($Recherche);
      }
    ?></select>                     
                       				<br />ddetails occupants: <br />
                                    <select name="situation2">
                                      <option value="" selected="selected"></option>
                                      <?php
    do {  
    ?>
                                      <option value="<?php echo $row_Recherche['situation2']?>"><?php echo $row_Recherche['situation2']?></option>
                                      <?php
    } while ($row_Recherche = mysql_fetch_assoc($Recherche));
      $rows = mysql_num_rows($Recherche);
      if($rows > 0) {
          mysql_data_seek($Recherche, 0);
    	  $row_Recherche = mysql_fetch_assoc($Recherche);
      }
    ?></select>               
                                   <br />comportement: <br />
                                   <select name="comportement">
                                     <option value="" selected="selected"></option>
                                     <?php
    do {  
    ?>
                                     <option value="<?php echo $row_Recherche['comportement']?>"><?php echo $row_Recherche['comportement']?></option>
                                     <?php
    } while ($row_Recherche = mysql_fetch_assoc($Recherche));
      $rows = mysql_num_rows($Recherche);
      if($rows > 0) {
          mysql_data_seek($Recherche, 0);
    	  $row_Recherche = mysql_fetch_assoc($Recherche);
      }
    ?></select>                      <br />satde reproduction: <br />
                                   <select name="stad_repro">
                                     <option value="" selected="selected"></option>
                                     <?php
    do {  
    ?>
                                     <option value="<?php echo $row_Recherche['stad_repro']?>"><?php echo $row_Recherche['stad_repro']?></option>
                                     <?php
    } while ($row_Recherche = mysql_fetch_assoc($Recherche));
      $rows = mysql_num_rows($Recherche);
      if($rows > 0) {
          mysql_data_seek($Recherche, 0);
    	  $row_Recherche = mysql_fetch_assoc($Recherche);
      }
    ?></select>
     
     
      <input type="submit" value="Valider" /><br /></form>
    <?php
    mysql_free_result($Recherche);
    ?>
    et m page resultat:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    <?php
    @session_start();
    include "connection.php"; 
     
    ini_set('error_reporting', 'E_ALL ^ E_NOTICE');
     
     
    $test=0;
    $name = $_POST['name'] ;
    $address = $_POST['address'] ;
    $region = $_POST['region'] ;
    $situation = $_POST['situation'] ;
    $situation2 = $_POST['situation2'] ;
    $nbrfau = $_POST['nrbfau'] ;
    $comportement = $_POST['comportement'] ;
    $stad_repo = $_POST['stad_repro'] ;
    $nbrpouss = $_POST['nbrpouss'] ;
    $oeuf_pouss = $_POST['oeuf_pouss'] ;
    $observation = $_POST['observation'] ;
    $nbrjuv = $_POST['nbrjuv'] ;
     
     
     
     
     
      $query =('SELECT * FROM markers');
      if  ($name!="" || $address!="" || $region!="" || $situation!="" || $situation2!="" || $nbrfau!="" || $comportement!="" || $stad_repro!="" || $nbrpouss!="" || $oeuf_pouss!="" || $observation!="" || $nbrjuv!="") {$query.=" WHERE ";}
     
      if ($name!="") {$query.=" (name  like '%$name%' OR  name like '%$name%' OR name like '%$name%') "; $t=1; }
     
      if ($t==1  && $address!=""){$query.=" AND ";}
      if ($address!="") {$query.=" (address  like '%$address%' OR address like '%$address%' OR address like '%$address%') "; $s=1; }
     
      if ($s==1 && $region !=""){$query.=" AND "; $v=0;}
      if ($v==0 && ($t==1 && $region !="")) {$query.=" AND "; $v=0;}
      if ($region !="") {$query.=" (region   like '%region %' OR region  like '%$region %' OR region  like '%$region %') ";  }
     
      if ($s==1 && $situation !=""){$query.=" AND "; $v=0;}
      if ($v==0 && ($t==1 && $situation !="")) {$query.=" AND "; $v=0;}
      if ($situation!="") {$query.=" (situation  like '%$situation%' OR situation like '%$situation%' OR situation like '%$situation%') "; $s=1; }
     
      if ($s==1 && $situation2 !=""){$query.=" AND "; $v=0;}
      if ($v==0 && ($t==1 && $situation2 !="")) {$query.=" AND "; $v=0;}
      if ($situation2!="") {$query.=" (situation2  like '%$situation2%' OR situation2 like '%$situation2%' OR situation2 like '%$situation2%') "; $s=1; }
     
      if ($s==1 && $nbrfau !=""){$query.=" AND "; $v=0;}
       if ($v==0 && ($t==1 && $nbrfau !="")) {$query.=" AND "; $v=0;}
      if ($nbrfau !="") {$query.=" (nrbfau   like '%nrbfau%' OR nrbfau  like '%$nrbfau%' OR nrbfau  like '%$nrbfau%') "; }
     
      if ($s==1 && $comportement !=""){$query.=" AND "; $v=0;}
      if ($v==0 && ($t==1 && $comportement !="")) {$query.=" AND "; $v=0;}
      if ($comportement!="") {$query.=" (comportement like '%$comportement%' OR comportement like '%$comportement%' OR comportement like '%$comportement%') "; $s=1;}
     
      if ($s==1 && $stad_repro !=""){$query.=" AND "; $v=0;}
      if ($v==0 && ($t==1 && $stad_repro !="")) {$query.=" AND "; $v=0;}
      if ($stad_repro!="") {$query.=" (stad_repro  like '%$stad_repro%' OR stad_repro like '%$stad_repro%' OR stad_repro like '%$stad_repro%') "; $s=1; }
     
      if ($s==1 && $nbrpouss !=""){$query.=" AND "; $v=0;}
      if ($v==0 && ($t==1 && $nbrpouss !="")) {$query.=" AND "; $v=0;}
      if ($nbrpouss !="") {$query.=" (nbrpouss   like '%nbrpouss %' OR nbrpouss  like '%$nbrpouss %' OR nbrpouss like '%$nbrpouss %') "; }
     
     
      if ($s==1 && $oeuf_pouss !=""){$query.=" AND "; $v=0;}
      if ($v==0 && ($t==1 && $oeuf_pouss !="")) {$query.=" AND "; $v=0;}
      if ($oeuf_pouss!="") {$query.=" (oeuf_pouss  like '%$oeuf_pouss%' OR oeuf_pouss '%$oeuf_pouss%' OR oeuf_pouss like '%oeuf_pouss%') "; $t=1; }
     
      if ($s==1 && $observation !=""){$query.=" AND "; $v=0;}
      if ($v==0 && ($t==1 && $stad_repro !="")) {$query.=" AND "; $v=0;}
      if ($observation!="") {$query.=" (observation  like '%$observation%' OR observation like '%$observation%' OR observation like '%$observation%') "; $s=1; }
     
      if ($s==1 && $nbrjuv !=""){$query.=" AND "; $v=0;}
       if ($v==0 && ($t==1 && $nbrjuv !="")) {$query.=" AND "; $v=0;}
      if ($nbrjuv !="") {$query.=" (nbrjuv   like '%nbrjuv %' OR nbrjuv  like '%$nbrjuv %' OR nbrjuv like '%nbrjuv %') "; }
     
     
    echo $query;
    $query2 = mysql_query($query)or die(mysql_error());
     
    ?>
    <table width="200" border="1">
      <tr>
        <th scope="col">nom site</th>
        <th scope="col">lieu</th>
        <th scope="col">region</th>
      	<th scope="col">statut</th>
        <th scope="col">details occupant</th>
        <th scope="col">nombre faucon</th>
      	<th scope="col">comportement</th>
        <th scope="col">stade reproduction</th>
        <th scope="col">nombre poussin</th>
      	<th scope="col">estimation</th>
        <th scope="col">observation</th>
        <th scope="col">nombre juvenil</th>
     
     
      </tr>
    <?php
    while ($r = mysql_fetch_assoc ($query2)) {
    ?>  <tr>
        <td><?php  echo $r['name'];?></td>
        <td><?php  echo $r['address'];?></td>
        <td><?php  echo $r['region'];?></td>
     	<td><?php  echo $r['situation'];?></td>
        <td><?php  echo $r['situation2'];?></td>
        <td><?php  echo $r['nrbfau'];?></td>
     	<td><?php  echo $r['comportement'];?></td>
        <td><?php  echo $r['stad_repro'];?></td>
        <td><?php  echo $r['nbrpouss'];?></td>
     	<td><?php  echo $r['oeuf_pouss'];?></td>
        <td><?php  echo $r['observation'];?></td>
        <td><?php  echo $r['nbrjuv'];?></td>
     
     
     
      </tr>
      <?php }?>
    </table>
    et une dexieme chose je voudrai faire des recherche par année, dans ma bdd j'ai un champs date au format (yyyy/dd/mm) ,mais je vois pas trop comment effectuer la requête sur ce champs

  2. #2
    Expert confirmé
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Billets dans le blog
    12
    Par défaut
    Bonjour,

    je n'ai parcouru que le 1er script et je dois dire qu'il est difficilement compréhensible.
    Je vais essayer de comprendre : tu veux faire des listes de sélection qui une fois sélectionnées et formulaire soumis, devront s'agglomérer pour former qu'un seul et unique critère afin de filtrer une requête. C'est ça, j'ai bon ?
    Si c'est ça, je pense qu'il faille tout reprendre depuis le début parce que tu t'es embarqué dans une voie sans issue.
    Pourrais-tu poster la structure de ta table markers, stp ?

  3. #3
    Membre averti
    Homme Profil pro
    Inscrit en
    Décembre 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2011
    Messages : 20
    Par défaut
    merci pour ta réponse
    oui et non
    le but c'est de sélectionner des critère grâce au option select, et qu’une fois le formulaire soumis il m'affiche un tableau avec toute les valeurs de la table correspondant a ce ou ces critères
    par exemple il choisis une année (2012 et ça lui affiche tout les entrés enregistrés de l'année 2012)
    pour la struture de markers:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    CREATE TABLE IF NOT EXISTS `markers` (
      `id` varchar(2) DEFAULT NULL,
      `name` varchar(50) DEFAULT NULL,
      `lat` float(10,6) DEFAULT NULL,
      `lng` float(10,6) DEFAULT NULL,
      `region` varchar(30) DEFAULT NULL,
      `address` varchar(30) DEFAULT NULL,
      `situation` varchar(20) DEFAULT NULL,
      `situation2` varchar(20) DEFAULT NULL,
      `nrbfau` int(5) DEFAULT NULL,
      `stad_repro` varchar(15) DEFAULT NULL,
      `nbrpouss` int(5) DEFAULT NULL,
      `oeuf_pouss` varchar(15) DEFAULT NULL,
      `nbrjuv` int(5) DEFAULT NULL,
      `observation` varchar(500) DEFAULT NULL,
      `dateobs` date DEFAULT NULL,
      `duree` int(11) DEFAULT NULL,
      `duree1` int(11) DEFAULT NULL,
      `comportement` varchar(30) DEFAULT NULL,
      `heure` time DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    pour ce qui est de la table resultat je l'ai modifier mais ça marche toujours pas:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    <?php
    @session_start();
    include "connection.php"; 
     
    ini_set('error_reporting', 'E_ALL ^ E_NOTICE');
     
     
    $test=0;
    $name = $_POST['name'] ;
    $address = $_POST['address'] ;
    $region = $_POST['region'] ;
     
      $query =("select * from markers where 'a'='a'");
     
    if ($name!="") { $query .= " AND (name  like '%$name%' OR  name like '%$name%' OR name like '%$name%') "; }
     
    if ($address!="") { $query .= " AND ( address  like '%$address%' OR address like '%$address%' OR address like '%$address%') "; }
     
    if ($region !="") { $query .= " AND (region   like '%region %' OR region  like 
    '%$region %' OR region  like '%$region %') ";  }
     
    if ($situation!="") { $query .= " AND (situation  like '%$situation%' OR situation like '%$situation%' OR situation like '%$situation%') ";}
     
    if ($situation2!="") { $query .= " AND (situation2  like '%$situation2%' OR situation2 like '%$situation2%' OR situation2 like '%$situation2%') ";  }
     
    if ($nbrfau !="") { $query .= " AND (nrbfau   like '%nrbfau%' OR nrbfau  like '%$nrbfau%' OR nrbfau  like '%$nrbfau%') "; }
     
    if ($comportement!="") { $query .= " AND (comportement like '%$comportement%' OR comportement like '%$comportement%' OR comportement like '%$comportement%') ";}
     
    if ($stad_repro!="") { $query .= " AND (stad_repro  like '%$stad_repro%' OR stad_repro like '%$stad_repro%' OR stad_repro like '%$stad_repro%') ";}
     
     if ($nbrpouss !="") { $query .= " AND (nbrpouss   like '%nbrpouss %' OR nbrpouss  like '%$nbrpouss %' OR nbrpouss like '%$nbrpouss %') "; }
     
     if ($oeuf_pouss!="") { $query .= " AND (oeuf_pouss  like '%$oeuf_pouss%' OR oeuf_pouss '%$oeuf_pouss%' OR oeuf_pouss like '%oeuf_pouss%') ";  }
     
      if ($observation!=""){ $query .= " AND (observation  like '%$observation%' OR observation like '%$observation%' OR observation like '%$observation%') "; }
     
      if ($nbrjuv !=""){ $query .= " AND (nbrjuv  like '%nbrjuv%' OR nbrjuv  like '%$nbrjuv %' OR nbrjuv like '%nbrjuv%') "; }
     
    echo $query;
    $query2 = mysql_query($query)or die(mysql_error());
     
    ?>
    <table width="200" border="1">
      <tr>
        <th scope="col">nom site</th>
        <th scope="col">lieu</th>
        <th scope="col">region</th>
      	<th scope="col">statut</th>
        <th scope="col">details occupant</th>
        <th scope="col">nombre faucon</th>
      	<th scope="col">comportement</th>
        <th scope="col">stade reproduction</th>
        <th scope="col">nombre poussin</th>
      	<th scope="col">estimation</th>
        <th scope="col">observation</th>
        <th scope="col">nombre juvenil</th>
     
     
      </tr>
    <?php
    while ($r = mysql_fetch_assoc ($query2)) {
    ?>  <tr>
        <td><?php  echo $r['name'];?></td>
        <td><?php  echo $r['address'];?></td>
        <td><?php  echo $r['region'];?></td>
     	<td><?php  echo $r['situation'];?></td>
        <td><?php  echo $r['situation2'];?></td>
        <td><?php  echo $r['nrbfau'];?></td>
     	<td><?php  echo $r['comportement'];?></td>
        <td><?php  echo $r['stad_repro'];?></td>
        <td><?php  echo $r['nbrpouss'];?></td>
     	<td><?php  echo $r['oeuf_pouss'];?></td>
        <td><?php  echo $r['observation'];?></td>
        <td><?php  echo $r['nbrjuv'];?></td>
     
     
     
      </tr>
      <?php }?>
    </table>
    j’espère avoir été plus clair

  4. #4
    Expert confirmé
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Billets dans le blog
    12
    Par défaut
    Bonsoir,

    J'avais 5min et j'en ai profité pour reprendre ton code intégralement histoire de te mettre sur la bonne voie.
    Voici la source du script du tableau résultat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    <?php
     
    session_start();
    ini_set('error_reporting', 'E_ALL ^ E_NOTICE');
     
    include "connection.php";
     
    // sécurisation de l'affichage
    $hsc = function($p) { return htmlspecialchars($p, ENT_QUOTES); };
     
    // montage du critère pour le sql 
    // je considère que la clé du tableau $_POST est identique au nom du champ de la table
    $filter =
       function($key)
       {
          return (isset($_POST[$key]) && strlen($_POST[$key]))
                    ? "$key LIKE '%".mysql_real_escape_string($_POST[$key])."%'"
                    : null;
       };
     
    $where   = array();
    $where[] = $filter('name');
    $where[] = $filter('adress');
    $where[] = $filter('region');
    $where[] = $filter('situation');
    $where[] = $filter('situation2');
    $where[] = $filter('nbrfau');
    $where[] = $filter('comportement');
    $where[] = $filter('stad_repro');
    $where[] = $filter('nbrpouss');
    $where[] = $filter('oeuf_pouss');
    $where[] = $filter('observation');
    $where[] = $filter('nbrjuv');
     
    // on retire les filtres sans données
    $cleanWhere = array_filter($where);
    $sqlWhere   = (empty($cleanWhere)) ? null : ' WHERE '.implode(' AND ', $cleanWhere);
     
    // requête
    $sql = 'SELECT * FROM markers'.$sqlWhere;
    $qry = mysql_query($sql) or die(mysql_error());
    $nb  = mysql_num_rows($qry);
     
    ?>
    <table width="200" border="1">
       <thead>
          <tr>
             <th scope="col">nom site</th>
             <th scope="col">lieu</th>
             <th scope="col">region</th>
             <th scope="col">statut</th>
             <th scope="col">details occupant</th>
             <th scope="col">nombre faucon</th>
             <th scope="col">comportement</th>
             <th scope="col">stade reproduction</th>
             <th scope="col">nombre poussin</th>
             <th scope="col">estimation</th>
             <th scope="col">observation</th>
             <th scope="col">nombre juvenil</th>
          </tr>
       </thead>
       <tbody>
          <?php if ($nb === 0): ?>
          <tr>
             <td colspan="12">Aucun résultat</td>
          </tr>
          <?php
             else:
                while($row = mysql_fetch_assoc($qry)): ?>
          <tr>
             <td><?php echo $hsc($row['name']); ?></td>
             <td><?php echo $hsc($row['address']); ?></td>
             <td><?php echo $hsc($row['region']); ?></td>
             <td><?php echo $hsc($row['situation']); ?></td>
             <td><?php echo $hsc($row['situation2']); ?></td>
             <td><?php echo $hsc($row['nrbfau']); ?></td>
             <td><?php echo $hsc($row['comportement']); ?></td>
             <td><?php echo $hsc($row['stad_repro']); ?></td>
             <td><?php echo $hsc($row['nbrpouss']); ?></td>
             <td><?php echo $hsc($row['oeuf_pouss']); ?></td>
             <td><?php echo $hsc($row['observation']); ?></td>
             <td><?php echo $hsc($row['nbrjuv']); ?></td>
          </tr>
          <?php endwhile;
             endif; ?>
       </tbody>
    </table>
    Une remarque dans ta table tu as un champ nommé nrbfau et dans ton sql tu fais le critère avec $_POST['nbrfau'] -> pas le même id alors que tous les autres suivent le règle -> clé de $_POST = nom du champ de la table.
    Bon courage

  5. #5
    Membre averti
    Homme Profil pro
    Inscrit en
    Décembre 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2011
    Messages : 20
    Par défaut
    merci
    je vais faire quelque tests mais pour l'instant ça fonctionne bien, je laisse ouvert le topique si jamais j'ai d'autre questions

Discussions similaires

  1. Recherche debugger PHP
    Par fleur_de_rose dans le forum Zend
    Réponses: 13
    Dernier message: 11/01/2012, 13h44
  2. Champ de recherche multiple avec php mysql
    Par glodybiss4 dans le forum PHP & Base de données
    Réponses: 18
    Dernier message: 29/12/2011, 17h48
  3. Recherche script PHP carnet d'adresses
    Par raffa dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 3
    Dernier message: 19/05/2006, 11h35
  4. [Tableaux] Recherche code php
    Par VFone dans le forum Langage
    Réponses: 7
    Dernier message: 28/03/2006, 16h11
  5. [Tableaux] comment faire un moteur de recherche en php
    Par lindouchine dans le forum Langage
    Réponses: 4
    Dernier message: 23/03/2006, 23h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo