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

Langage PHP Discussion :

recherche multicritère


Sujet :

Langage PHP

  1. #1
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut recherche multicritère
    Bonjour,

    Je suis débutante en php,je veux créer une application qui récupère les données a partir d'une base de donnée mysql ,j'ai réussi a récupérer les données mais le problème est dont le filtre.

    j'ai plusieurs tables dans la base de donnée produit,categorie et societe je veux que ma liste de produit soit filtré selon le produit,la catégorie et la société sélectionnés

    j'arrive a filtrer selon un seul critère (le premier if) le reste sont pas exécute .
    Merci.

    Voici le code :
    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
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    <?php
     
    if(isset($_POST['search']))
     
    {   
    	 if (isset($_POST['produit'])) // si une region à été choisie
    {
          $id_p=$_POST['produit'];
          }else{
        $id_p = 'vide';
       }
     
     if (isset($_POST['categorie'])) // si un producteur à été choisie
    {
          $id_cat=$_POST['categorie'];
          } else{
        $id_cat = 'vide';
       }
     
    if (isset($_POST['societe'])) // envoi de la region lorsque le producteur est selectionne
    {
          $id_s=$_POST['societe'];
          }else{
        $id_s = 'vide';
     
       } 
     
    	if ($id_p != 'vide'){
     
     
     
        $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorie FROM produit p, societe s,Categories c WHERE p.id_s = s.id_s and p.id_cat=c.id_cat and p.id_p='$id_p'";
        $search_result = filterTable($query);
     
    }
     
    elseif ($id_s != 'vide'){
        $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorie FROM produit p, societe s,Categories c WHERE p.id_s = s.id_s and p.id_cat=c.id_cat and s.id_s='$id_s'";
        $search_result = filterTable($query);
     
    }
     
    	elseif ($id_cat != 'vide'){
        $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorie FROM produit p, societe s,Categories c WHERE p.id_s = s.id_s and p.id_cat=c.id_cat and c.id_cat='$id_cat'";
        $search_result = filterTable($query);
     
    }	
    	elseif (($id_cat != 'vide') and($id_p != 'vide')) {
        $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorie FROM produit p, societe s,Categories c WHERE p.id_s = s.id_s and p.id_cat=c.id_cat and c.id_cat='$id_cat' and p.id_p='$id_p'";
        $search_result = filterTable($query);
     
    }	elseif (($id_cat != 'vide') and($id_s != 'vide')) {
        $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorie FROM produit p, societe s,Categories c WHERE p.id_s = s.id_s and p.id_cat=c.id_cat and c.id_cat='$id_cat' and s.id_s='$id_s'";
        $search_result = filterTable($query);
     
    }		
     
    elseif (($id_s != 'vide') and($id_p != 'vide')) {
        $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorieFROM produit p, societe s,Categories c WHERE p.id_s = s.id_s and p.id_cat=c.id_cat and s.id_s='$id_s' and p.id_p='$id_p'";
        $search_result = filterTable($query);
     
    }		
     
    elseif (($id_cat != 'vide') and($id_p != 'vide')and($id_s != 'vide')) {
        $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorie FROM produit p, societe s,Categories c WHERE p.id_s = s.id_s and p.id_cat=c.id_cat and c.id_cat='$id_cat' and p.id_p='$id_p' and s.id_s='$id_s'";
        $search_result = filterTable($query);
     
    }	
     
     
     
    }
     
     
     else {
    	   include("Connection.php");
           $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorie FROM produit p, societe s,Categories c WHERE p.id_s = s.id_s and p.id_cat=c.id_cat";
        $search_result = filterTable($query);
    }
     
    // function to connect and execute the query
    function filterTable($query)
    {  include("Connection.php");
        $filter_Result = mysqli_query($connect, $query);
     
        return $filter_Result;
    }
     
    ?>
     
    <!DOCTYPE html>
    <html>
        <head>
              <?php include("HeaderAdmin.html"); ?>
        </head>
        <body>
           <form id="ajouterfclient" method="post"  action="liste.php">
            <h1 style="color :red">Application Agriculture</h1>
     
    		<div class="col-sm-8">
                <table class="table table-striped">
                    <thead></thead>
                    <tbody>
                    <tr>
    				 <td width=100 style ="color:#006400"> <SELECT class="form-control" name="produit"><br><br>
               <option value=-1>--produit--</option>
                    <?php include("Connection.php");
     
     
     
     
     
                    $req=	mysqli_query($connect,"SELECT * FROM produit ");
    				mysqli_query($connect,"SET NAMES 'utf8'");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                        <option value="<?php echo utf8_encode($data['id_p']) ?>"> <?php echo utf8_encode($data['nom'])  ?></option>
                    <?php } ?> 
                </SELECT> </td>
    			 <td width=300 style ="color:#006400"> <SELECT class="form-control" name="categorie">
               <option value=-1>--Categorie-- </option>
                    <?php include("Connection.php");
     
     
     
     
     
                    $req=	mysqli_query($connect,"SELECT * FROM Categories ");
    				mysqli_query($connect,"SET NAMES 'utf8'");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                        <option value="<?php echo utf8_encode($data['id_cat']) ?>"> <?php echo utf8_encode($data['categorie'])  ?></option>
                    <?php } ?> 
                </SELECT> </td>
     
     
    			 	 <td width=300 style ="color:#006400">
    				  <SELECT class="form-control" name="societe">
               <option value=-1>--Societe-- </option>
                    <?php include("Connection.php");
                    mysqli_select_db($connect,'fito');
                    $req=	mysqli_query($connect,"SELECT * FROM societe ");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                <option value="<?php echo utf8_encode($data['id_s']) ?>"> <?php echo utf8_encode($data['nom_s'])  ?></option>
                    <?php } ?> 
                </SELECT></td>
    			 <td > </td >
                         <td >  <input type="submit" name="search" value="Filter"> </td >
     
     
     
                <table>  
     
     
     
     
                    <?php while($row = mysqli_fetch_array($search_result)):?>
                    <tr class="active">
     
     
                                              <td><?php echo $row['nom'];?></td>
    					    <td><?php echo $row['categorie'];?></td>
    					    <td><?php echo $row['nom_s'];?></td>
    					  <td><a class="btn btn-primary" href="ModifierProduitI.php?id=<?php echo $row['id_p'];?>"> Détail</a> </td>
     
                    </tr>
                    <?php endwhile;?>
     
     
                </table>
            </form>
     
        </body>
    </html>

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Il ne faut pas écrire tous les cas possibles, imagine que tu aies 5 critères.
    Il suffit d'assembler les conditions selon qu'elles existent ou non :
    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
    <?php
     
    if (isset($_POST['produit'])) // si une region à été choisie
    {
        $where[] = ' p.id_p = ' . mysqli_real_escape_string($_POST['produit']);
    }
     
     if (isset($_POST['categorie'])) // si un producteur à été choisie
    {
    	$where[] = ' c.id_cat = ' . mysqli_real_escape_string($_POST['categorie']);
    }
     
    if (isset($_POST['societe'])) // envoi de la region lorsque le producteur est selectionne
    {
    	$where[] = ' s.id_s = ' . mysqli_real_escape_string($_POST['societe']);
    }
     
    $query = "SELECT DISTINCT s.id_s, s.nom_s, p.nom,p.id_p,c.id_cat,c.categorie 
    			FROM societe s 
    			JOIN produit p ON p.id_s = s.id_s
    			JOIN Categories ON p.id_cat=c.id_cat";
    if (isset($where)) {
    	$query .= " WHERE " . implode(' AND ', $where);
    }
     
    $search_result = filterTable($query);
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut recherche multicritére php
    Merci pour votre réponse, mais le filtre ne fonctionne pas.
    j'ai changé la requête sql pour afficher les produits (supprimer les join)

    Voici le code :
    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
    <?php
     
     if(isset($_POST['search']))
     
    {   
     
         include("Connection.php");
     
    if (isset($_POST['produit'])) // si une region à été choisie
    {
        $where[] = ' p.id_p = ' . mysqli_real_escape_string($_POST['produit']);
    }
     
     if (isset($_POST['categorie'])) // si un producteur à été choisie
    {
    	$where[] = ' c.id_cat = ' . mysqli_real_escape_string($_POST['categorie']);
    }
     
    if (isset($_POST['societe'])) // envoi de la region lorsque le producteur est selectionne
    {
    	$where[] = ' s.id_s = ' . mysqli_real_escape_string($_POST['societe']);
    }
     
    $query = "SELECT DISTINCT s.id_s,
    	   s.nom_s, p.nom,p.images, p.id_p, p.formul,
    	   p.n_hmlg, p.concentration,c.id_cat,c.categorie
    	   FROM produit p, societe s,Categories c 
    	   WHERE p.id_s = s.id_s and p.id_cat=c.id_cat";
     
    if (isset($where)) {
    	$query .= " WHERE " . implode(' AND ', $where);
     
    }
     $search_result = filterTable($query); 
     
     
    }else {
    	   include("Connection.php");
           $query = "SELECT DISTINCT s.id_s,
    	   s.nom_s, p.nom,p.images, p.id_p, p.formul,
    	   p.n_hmlg, p.concentration,c.id_cat,c.categorie
    	   FROM produit p, societe s,Categories c 
    	   WHERE p.id_s = s.id_s and p.id_cat=c.id_cat";
        $search_result = filterTable($query);
    }
     
     
    // function to connect and execute the query
    function filterTable($query)
    {  include("Connection.php");
        $filter_Result = mysqli_query($connect, $query);
     
        return $filter_Result;
    }
     
    ?>

  4. #4
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    $query = "SELECT DISTINCT s.id_s,
    	...
    	   WHERE p.id_s = s.id_s and p.id_cat=c.id_cat";
    ...
    	$query .= " WHERE " . implode(' AND ', $where);

    1/ il ne peut pas y avoir 2 WHERE dans une requête SQL.

    2/ on utilise des JOINTURES quand on a plusieurs tables :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    	   FROM produit p, societe s,Categories c 
    	   WHERE p.id_s = s.id_s and p.id_cat=c.id_cat";
    A remplacer par (COMME l'a écrit sabotage dans son code !) :
    Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    	   FROM produit p
    	   INNER JOIN societe s
    	     ON p.id_s = s.id_s
    	   INNER JOIN Categories c 
    	     ON p.id_cat=c.id_cat
    Et le tour est joué.

  5. #5
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut recherche multicritére
    Merci bc pour votre reponse,

    C'est vrai la requette sql avec les join fonctionne,j'arrive a afficher toutes la liste de produit,mais le filtre ne fonctionne toujours pas et je vois pas ou est le problème.

    quand je filtre il me retourne une liste qui est vide.

  6. #6
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Montre nous ton code actuel et la chaine de requête que tu obtiens quand tu mets un filtre.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  7. #7
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut recherche multicritere
    J'ai fais meme des 'echo ' la requete de filtre est executé mais le resultat est vide.
    voici le code:


    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
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
     
    <!DOCTYPE html>
    <html>
    <head>
        <title>Adminstrator</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
          <link rel="stylesheet" href="css/stylesheet.css" />
        <link rel="stylesheet" href="css/stylesheet_pageAjout.css" />  
    	<link rel="stylesheet" href="css/bootstrap.min.css" />
     
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/script.js"></script>
        <title>DZ UP </title>
    </head>
    <body>
     
    <header>
        <?php include("HeaderAdmin.html"); ?>
    </header>
    <section class="section">
     
    <?php
     
     
         include("Connection.php");
     
    $query = "SELECT DISTINCT s.id_s, s.nom_s, p.images,p.nom,p.id_p,c.id_cat,c.categorie 
    			FROM produit p 
    			JOIN societe s ON p.id_s = s.id_s
    			JOIN Categories c ON p.id_cat=c.id_cat";	
    $search_result = filterTable($query);
    echo'good';			
     
    if(isset($_POST['search']))
     
    {  
    if (isset($_POST['produit'])) 
    {
        $where[] = ' p.id_p = ' . mysqli_real_escape_string($_POST['produit']);
     
    }
     
     if (isset($_POST['categorie'])) 
    {
    	$where[] = ' c.id_cat = ' . mysqli_real_escape_string($_POST['categorie']);
    }
     
    if (isset($_POST['societe'])) 
    {
    	$where[] = ' s.id_s = ' . mysqli_real_escape_string($_POST['societe']);
    }
     
     
     
     
     
     
     
    if (isset($where)) {
     
    	$query .= " WHERE " . implode(' AND ', $where);
    	$search_result = filterTable($query);
    	echo'yes';
    }
     
     
     
    }
     
     
     
     
     
     
    // function to connect and execute the query
    function filterTable($query)
    {  include("Connection.php");
        $filter_Result = mysqli_query($connect, $query);
     
        return $filter_Result;
    }
     
     
     
    ?>
     
    <!DOCTYPE html>
    <html>
        <head>
              <?php include("HeaderAdmin.html"); ?>
        </head>
        <body>
           <form id="ajouterfclient" method="post"  action="liste.php">
            <h1 style="color :red">Application Agriculture</h1>
     
    		<div class="col-sm-8">
                <table class="table table-striped">
                    <thead></thead>
                    <tbody>
                    <tr>
    				 <td width=300 style ="color:#006400"> <SELECT class="form-control" name="produit"><br><br>
               <option value=-1>--produit--</option>
                    <?php include("Connection.php");
     
     
     
     
     
                    $req=	mysqli_query($connect,"SELECT * FROM produit ");
    				mysqli_query($connect,"SET NAMES 'utf8'");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                        <option value="<?php echo utf8_encode($data['id_p']) ?>"> <?php echo utf8_encode($data['nom'])  ?></option>
                    <?php } ?> 
                </SELECT> </td>
    			 <td width=300 style ="color:#006400"> <SELECT class="form-control" name="categorie">
               <option value=-1>--Categorie-- </option>
                    <?php include("Connection.php");
     
     
     
     
     
                    $req=	mysqli_query($connect,"SELECT * FROM Categories ");
    				mysqli_query($connect,"SET NAMES 'utf8'");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                        <option value="<?php echo utf8_encode($data['id_cat']) ?>"> <?php echo utf8_encode($data['categorie'])  ?></option>
                    <?php } ?> 
                </SELECT> </td>
     
     
    			 	 <td width=300 style ="color:#006400">
    				  <SELECT class="form-control" name="societe">
               <option value=-1>--Societe-- </option>
                    <?php include("Connection.php");
                    mysqli_select_db($connect,'fito');
                    $req=	mysqli_query($connect,"SELECT * FROM societe ");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                <option value="<?php echo utf8_encode($data['id_s']) ?>"> <?php echo utf8_encode($data['nom_s'])  ?></option>
                    <?php } ?> 
                </SELECT></td>
    			 <td > </td >
                         <td >  <input type="submit" name="search" value="Filter"> </td >
     
     
     
                <table>  
     
     
     
     
                    <?php while($row = mysqli_fetch_array($search_result)):?>
                    <tr class="active">
    				 <td><img src="<?php echo $row['images'] ?>" /></td>
     
                        <td><?php echo $row['nom'];?></td>
    					    <td><?php echo $row['categorie'];?></td>
    					    <td><?php echo $row['nom_s'];?></td>
    					  <td><a class="btn btn-primary" href="ModifierProduitI.php?id=<?php echo $row['id_p'];?>"> Détail</a> </td>
     
                    </tr>
                    <?php endwhile;?>
                </table>
            </form>
     
        </body>
    </html>

  8. #8
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Est-ce que la requête obtenue est bonne ? Donne t-elle des résultats dans PHPmyadmin ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  9. #9
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut
    oui la requête est bonne,et elle donne le résultat qui est ds phpmyadmin,le problème se pose juste au moment de filtre affichage vide.

  10. #10
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Tu veux dire une page entièrement blanche ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  11. #11
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut
    oui page blache.
    Images attachées Images attachées  

  12. #12
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    C'est pas une page blanche ça.

    Bref, contrôle ce que vaut $search_result.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  13. #13
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut recherche multicritére php
    Bonjour,
    Merci sabotage ,Votre code fonctionne quand je choisis les trois critères a la fois (produit and categorie and societe).

    mais quand je choisie seulement un seul critère exemple:produit ou bien produit and categorie le filtre ne marche pas .

    Merci pour votre aide.

  14. #14
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    merci de remontrer TON code.

  15. #15
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut recherche multicritére php
    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
    <?php
     
     
         include("Connection.php");
     
    $query = "SELECT DISTINCT s.id_s, s.nom_s, p.images,p.nom,p.id_p,c.id_cat,c.categorie 
    			FROM produit p 
    			JOIN societe s ON p.id_s = s.id_s
    			JOIN Categories c ON p.id_cat=c.id_cat";	
     
     
    if(isset($_POST['search']))
     
    {  
    if (isset($_POST['produit'])) 
    {
        $where[] = ' p.id_p = ' .($_POST['produit']);
     
    }
     
     if (isset($_POST['categorie'])) 
    {
    	$where[] = ' c.id_cat = ' .($_POST['categorie']);
    }
     
    if (isset($_POST['societe'])) 
    {
    	$where[] = ' s.id_s = ' .($_POST['societe']);
    }
     
    if (isset($where)) {
     
    $query = "SELECT DISTINCT s.id_s, s.nom_s, p.images,p.nom,p.id_p,c.id_cat,c.categorie 
    			FROM produit p 
    			JOIN societe s ON p.id_s = s.id_s
    			JOIN Categories c ON p.id_cat=c.id_cat WHERE " . implode(" AND ", $where) . " " ;	
     
     
    }
     
    }
    	$search_result = filterTable($query);
     
    function filterTable($query)
    {  include("Connection.php");
        $filter_Result = mysqli_query($connect, $query);
     
        return $filter_Result;
    }
     
     
     
    ?>

  16. #16
    Invité
    Invité(e)
    Par défaut
    Code php : 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
    <?php
    include("Connection.php");
     
    $where = array();
    if(isset($_POST['search']))
    {  
    	if ( !empty($_POST['produit']) ) 
    	{
    		$where[] = ' p.id_p = ' .mysqli_real_escape_string($_POST['produit']);
    	}
     
    	if ( !empty($_POST['categorie']) ) 
    	{
    		$where[] = ' c.id_cat = ' .mysqli_real_escape_string($_POST['categorie']);
    	}
     
    	if ( !empty($_POST['societe']) ) 
    	{
    		$where[] = ' s.id_s = ' .mysqli_real_escape_string($_POST['societe']);
    	}
    }
    $whereAnd = ( !empty($where) )? " WHERE " . implode(" AND ", $where) : '';
     
    $query = "SELECT DISTINCT s.id_s, s.nom_s, p.images, p.nom, p.id_p, c.id_cat, c.categorie 
    	FROM produit p 
    	JOIN societe s ON p.id_s = s.id_s
    	JOIN Categories c ON p.id_cat=c.id_cat".
    	$whereAnd;	
     
    $search_result = filterTable($query);
     
    function filterTable($query)
    {
    	global $connect;
    	$filter_Result = mysqli_query($connect, $query);
    	return $filter_Result;
    }
    ?>

  17. #17
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut
    Merci bc pour votre réponse,
    mais votre code donne le même résultat que mon code ,toujours il faut choisir tous les critères de recherche pour afficher le résultat.

  18. #18
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Essaye d'afficher la requête quand tu ne sélectionnes qu'un seul critère et de la tester dans PhpMyAdmin
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  19. #19
    Invité
    Invité(e)
    Par défaut
    Peut-on voir le code de ton formulaire ?

  20. #20
    Candidat au Club
    Femme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2016
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Octobre 2016
    Messages : 13
    Points : 4
    Points
    4
    Par défaut
    Bonjour,

    Celira jai affiché ma requête ,quand je sélectionne un seul critère il me récupère l'identifient mais il affiche pas le résultat a cause des and.
    exemple quand je sélectionne seulement produit :
    SELECT DISTINCT s.id_s, s.nom_s, p.images, p.nom, p.id_p, c.id_cat, c.categorie FROM produit p JOIN societe s ON p.id_s = s.id_s JOIN Categories c ON p.id_cat=c.id_cat WHERE p.id_p = 1 AND c.id_cat = --Categorie-- AND s.id_s = --Societe-- 
    Voici tous le code:
    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
    139
    140
    141
    142
    143
    144
    145
    146
    147
     
    <?php
     
     
         include("Connection.php");
     
    $query = "SELECT DISTINCT s.id_s, s.nom_s, p.images,p.nom,p.id_p,c.id_cat,c.categorie 
    			FROM produit p 
    			JOIN societe s ON p.id_s = s.id_s
    			JOIN Categories c ON p.id_cat=c.id_cat ";	
     
     
    $where = array();
    if(isset($_POST['search']))
    {  
    	if ( !empty($_POST['produit']) ) 
    	{
    		$where[] = ' p.id_p = ' .mysqli_real_escape_string($connect,$_POST['produit']);
    	}
     
    	if ( !empty($_POST['categorie']) ) 
    	{
    		$where[] = ' c.id_cat = ' .mysqli_real_escape_string($connect,$_POST['categorie']);
    	}
     
    	if ( !empty($_POST['societe']) ) 
    	{
    		$where[] = ' s.id_s = ' .mysqli_real_escape_string($connect,$_POST['societe']);
    	}
     
    $whereAnd = ( !empty($where) )? " WHERE " . implode(" AND ", $where) : '';
     
    $query = "SELECT DISTINCT s.id_s, s.nom_s, p.images, p.nom, p.id_p, c.id_cat, c.categorie 
    	FROM produit p 
    	JOIN societe s ON p.id_s = s.id_s
    	JOIN Categories c ON p.id_cat=c.id_cat".
    	$whereAnd;	
    	echo $query;
    }
    $search_result = filterTable($query);
     
    function filterTable($query)
    {
    	global $connect;
    	$filter_Result = mysqli_query($connect, $query);
    	return $filter_Result;
    }
    ?>
     
    <!DOCTYPE html>
    <html>
        <head>
              <?php include("HeaderAdmin.html"); ?>
        </head>
        <body>
           <form id="ajouterfclient" method="post"  action="apropos.php">
     
     
    		<div class="col-sm-8">
                <table class="table table-striped">
                    <thead></thead>
                    <tbody>
                    <tr>
    				 <td width=300 style ="color:#006400"> <SELECT class="form-control" id="produit" name="produit"  ><br><br>
               <option >--produit--</option>
                    <?php include("Connection.php");
     
     
     
     
     
                    $req=	mysqli_query($connect,"SELECT * FROM produit ");
    				mysqli_query($connect,"SET NAMES 'utf8'");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                        <option value="<?php echo utf8_encode($data['id_p']) ?>"> <?php echo utf8_encode($data['nom'])  ?></option>
                    <?php } ?> 
                </SELECT> </td>
    			 <td width=300 style ="color:#006400"> <SELECT class="form-control" id="categorie" name="categorie">
               <option >--Categorie-- </option>
                    <?php include("Connection.php");
     
     
     
     
     
                    $req=	mysqli_query($connect,"SELECT * FROM Categories ");
    				mysqli_query($connect,"SET NAMES 'utf8'");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                        <option value="<?php echo utf8_encode($data['id_cat']) ?>"> <?php echo utf8_encode($data['categorie'])  ?></option>
                    <?php } ?> 
                </SELECT> </td>
     
     
    			 	 <td width=300 style ="color:#006400">
    				  <SELECT class="form-control" id="societe" name="societe">
               <option>--Societe-- </option>
                    <?php include("Connection.php");
                    mysqli_select_db($connect,'fito');
                    $req=	mysqli_query($connect,"SELECT * FROM societe ");
     
                    while($data=mysqli_fetch_array($req, MYSQLI_ASSOC))
                    {
                        ?>
                <option value="<?php echo utf8_encode($data['id_s']) ?>"> <?php echo utf8_encode($data['nom_s'])  ?></option>
                    <?php } ?> 
                </SELECT></td>
    			 <td > </td >
                         <td > <input type="submit" name="search" value="Filter"> </td >
     
     
     
                <table>  
     
     
     
     
                    <?php while($row = mysqli_fetch_array($search_result)):?>
                    <ul class="active">
    				 <img src="<?php echo $row['images'] ?>" />
     
                        <li><?php echo $row['nom'];?></li>
    					    <li><?php echo $row['categorie'];?></li>
    					    <li><?php echo $row['nom_s'];?></li>
    					  <li><a class="btn btn-primary" href="ModifierProduitI.php?id=<?php echo $row['id_p'];?>"> Détail</a> </li>
                          <li style ="border: 1px solid #eee;"></li>
                    </ul>
                    <?php endwhile;?>
                </table>
            </form>
     
         <!-- Bootstrap core JavaScript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
     
      <script>
     
    </body>
     
    </html>

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. faire un état d'après recherche multicritère
    Par bilouk dans le forum Access
    Réponses: 4
    Dernier message: 12/01/2006, 18h30
  2. Formulaire Recherche MultiCritère et RunTime
    Par fbu78 dans le forum Runtime
    Réponses: 9
    Dernier message: 06/01/2006, 17h52
  3. Recherche multicritère
    Par Darlay Jean_Louis dans le forum Access
    Réponses: 2
    Dernier message: 26/10/2005, 09h54
  4. Réponses: 2
    Dernier message: 01/10/2005, 18h42
  5. recherche multicritères
    Par onlineduel dans le forum Débuter
    Réponses: 3
    Dernier message: 30/03/2004, 16h15

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