$requete = mysql_query($sql,$cnx) or die("ERREUR MYSQL numéro: ".mysql_errno()."<br>Type de cette erreur: ".mysql_error()."<br>\n" ); Echo "<br> <b>La requête est :</b><br> ".$sql; // La ligne suivante NE PEUT PAS fonctionner //print_r($requete); // Pour traiter le résultat de la requête ($requete) il faut utiliser le FETCH ... // Par exemple : .mysql-fetch-array : http://php.net/manual/fr/function.mysql-fetch-array.php while ($row = mysql_fetch_array($requete )) { // Ici le traitement ...par exemple avec un print print_r($row ); }
string implode ( string $glue , array $pieces )
// Code à remplacer : // for($j=1;$j<$i;$j++) // { // $critere .= " AND ".$choix[$j]." "; // } // PAR : $critere = implode( " AND " , $choix);
<?php // on récupère les critères sélectionnés extract($_POST); $color=array('#FFDFEF','#FFCEFF'); $i = 0; // si la variable est présente, on lui affecte une place dans le tableau 'choix[]', qui nous servira ensuite à construire le WHERE de la requête. //PRODUIT VERRE //PRODUIT PARAMETTE if(!empty($prejudiceMoraux3)) { $choix[$i++] = "prejudiceMoraux3 = '$prejudiceMoraux3'"; } if(!empty($prejudiceMoraux2)) { $choix[$i++] = "prejudiceMoraux2 = '$prejudiceMoraux2'"; } if(!empty($prejudiceMoraux1)) { $choix[$i++] = "prejudiceMoraux1 = '$prejudiceMoraux1'"; } if(!empty($localiteDEC)) { $choix[$i++] = "localiteDEC = '$localiteDEC'"; } if(!empty($communeDEC)) { $choix[$i++] = "communeDEC = '$communeDEC'"; } if(!empty($prefectDEC)) { $choix[$i++] = "prefectDEC = '$prefectDEC'"; } if(!empty($departDEC)) { $choix[$i++] = "departDEC = '$departDEC'"; } if(!empty($causedecedeD)) { $choix[$i++] = "causedecedeD = '$causedecedeD'"; } if(!empty($radios_0)) { $choix[$i++] = "radios_0 = '$radios_0'"; } if(!empty($lireV)) { $choix[$i++] = "lireV = '$lireV'"; } if(!empty($epouseD)) { $choix[$i++] = "epouseD = '$epouseD'"; } if(!empty($nomM)) { $choix[$i++] = "nomM = '$nomM'"; } if(!empty($prejudiceMoraux4)) { $choix[$i++] = "prejudiceMoraux4 = '$prejudiceMoraux4'"; } if(!empty($prejudiceMoraux5)) { $choix[$i++] = "prejudiceMoraux5 = '$prejudiceMoraux5'"; } if(!empty($prejudiceMoraux6)) { $choix[$i++] = "prejudiceMoraux6 = '$prejudiceMoraux6'"; } if(!empty($prejudiceMoraux7)) { $choix[$i++] = "prejudiceMoraux7 = '$prejudiceMoraux7'"; } if(!empty($prejudiceMoraux8)) { $choix[$i++] = "prejudiceMoraux8 = '$prejudiceMoraux8'"; } if(!empty($prejudiceMoraux9)) { $choix[$i++] = "prejudiceMoraux9 = '$prejudiceMoraux9'"; } if(!empty($prejudiceMoraux10)) { $choix[$i++] = "prejudiceMoraux10 = '$prejudiceMoraux10'"; } if(!empty($pejudiceMateriels1)) { $choix[$i++] = "pejudiceMateriels1 = '$pejudiceMateriels1'"; } if(!empty($pejudiceMateriels2)) { $choix[$i++] = "pejudiceMateriels2 = '$pejudiceMateriels2'"; } if(!empty($pejudiceMateriels3)) { $choix[$i++] = "pejudiceMateriels3 = '$pejudiceMateriels3'"; } if(!empty($pejudiceMateriels4)) { $choix[$i++] = "pejudiceMateriels4 = '$pejudiceMateriels4'"; } if(!empty($pejudiceMateriels5)) { $choix[$i++] = "pejudiceMateriels5 = '$pejudiceMateriels5'"; } if(!empty($pejudiceMateriels6)) { $choix[$i++] = "pejudiceMateriels6 = '$pejudiceMateriels6'"; } if(!empty($pejudiceMateriels7)) { $choix[$i++] = "pejudiceMateriels7 = '$pejudiceMateriels7'"; } if(!empty($pejudiceMateriels8)) { $choix[$i++] = "pejudiceMateriels8 = '$pejudiceMateriels8'"; } if(!empty($autreprejudices)) { $choix[$i++] = "autreprejudices = '$autreprejudices'"; } if(!empty($jugerV)) { $choix[$i++] = "jugerV = '$jugerV'"; } if(!empty($JdateInt)) { $choix[$i++] = "JdateInt = '$JdateInt'"; } if(!empty($MdateInt)) { $choix[$i++] = "MdateInt = '$MdateInt'"; } if(!empty($AdateInt)) { $choix[$i++] = "AdateInt = '$AdateInt'"; } if(!empty($JdateVerif)) { $choix[$i++] = "JdateVerif = '$JdateVerif'"; } if(!empty($MdateVerif)) { $choix[$i++] = "MdateVerif = '$MdateVerif'"; } if(!empty($AdateVerif)) { $choix[$i++] = "AdateVerif = '$AdateVerif'"; } if(!empty($Jdatecod)) { $choix[$i++] = "Jdatecod = '$Jdatecod'"; } if(!empty($Mdatecod)) { $choix[$i++] = "Mdatecod = '$Mdatecod'"; } if(!empty($Adatecod)) { $choix[$i++] = "Adatecod = '$Adatecod'"; } if(!empty($Jdatesaisi)) { $choix[$i++] = "Jdatesaisi = '$Jdatesaisi'"; } if(!empty($Mdatesaisi)) { $choix[$i++] = "Mdatesaisi = '$Mdatesaisi'"; } if(!empty($Adatesaisi)) { $choix[$i++] = "Adatesaisi = '$Adatesaisi'"; } if(!empty($agentcol)) { $choix[$i++] = "agentcol = '$agentcol'"; } if(!empty($chef)) { $choix[$i++] = "chef = '$chef'"; } if(!empty($agentcod)) { $choix[$i++] = "agentcod = '$agentcod'"; } if(!empty($dateagent)) { $choix[$i++] = "dateagent = '$dateagent'"; } if(!empty($observationV)) { $choix[$i++] = "observationV = '$observationV'"; } if(!empty($nomM)) { $choix[$i++] = "nomM = '$nomM'"; } if(!empty($jourD)) { $choix[$i++] = "jourD = '$jourD'"; } if(!empty($jourD)) { $choix[$i++] = "jourD = '$jourD'"; } if(!empty($moisD)) { $choix[$i++] = "moisD = '$moisD'"; } if(!empty($anneeD)) { $choix[$i++] = "anneeD = '$anneeD'"; } if(!empty($ageD)) { $choix[$i++] = "ageD = '$ageD'"; } if(!empty($departD)) { $choix[$i++] = "departD = '$departD'"; } if(!empty($prefectV)) { $choix[$i++] = "prefectV = '$prefectV'"; } if(!empty($telVDAR)) { $choix[$i++] = "telVDAR = '$telVDAR'"; } if(!empty($localiteVDAR)) { $choix[$i++] = "localiteVDAR = '$localiteVDAR'"; } if(!empty($communeVDAR)) { $choix[$i++] = "communeVDAR = '$communeVDAR'"; } if(!empty($prefectVDAR)) { $choix[$i++] = "prefectVDAR = '$prefectVDAR'"; } if(!empty($departVDAR)) { $choix[$i++] = "departVDAR = '$departVDAR'"; } if(!empty($localiteVDA)) { $choix[$i++] = "localiteVDA = '$localiteVDA'"; } if(!empty($sexeV)) { $choix[$i++] = "sexeV = '$sexeV'"; } if(!empty($autreLienV)) { $choix[$i++] = "autreLienV = '$autreLienV'"; } if(!empty($lienV)) { $choix[$i++] = "lienV = '$lienV'"; } if(!empty($epouseV)) { $choix[$i++] = "epouseV = '$epouseV'"; } if(!empty($prenomV)) { $choix[$i++] = "prenomV = '$prenomV'"; } if(!empty($nomV)) { $choix[$i++] = "nomV = '$nomV'"; } $critere = $choix[0]." "; // for($j=1;$j<$i;$j++) //{ // $critere .= " AND ".$choix[$j]." "; // } $critere = implode( " AND " , $choix); // enfin on fait la requête si $i >0, ça veut dire qu'il y a des critères if($i > 0) { $sql = "SELECT * FROM victime V ,agent A ,tb_departement D ,tb_sous_prefecture SP ,tb_commune C ,tb_localite L ,prejudicemateriel PREJMAT ,infogenerale INF ,prejudicemoraux PREJMo WHERE $critere AND V.matricule = A.id AND A.id = D.id AND D.id = SP.id AND SP.id = C.id AND C.id = L.id AND L.id = PREJMAT.id_prejMat AND PREJMAT.id_prejMat = INF.id_infoG AND INF.id_infoG = PREJMo.id_prejM GROUP BY V.matricule "; $requete = mysql_query($sql,$cnx) or die( "ERREUR MYSQL numéro: ".mysql_errno()."<br>Type de cette erreur: ".mysql_error()."<br>\n" ); $n = mysql_num_rows($requete ); echo "<br> <b>La requête est :</b><br> ".$sql; ?>
$critere = implode( " AND " , $choix); // enfin on fait la requête si $i >0, ça veut dire qu'il y a des critères if($i > 0) { $sql = "SELECT * FROM victime V ,agent A ,tb_departement D ,tb_sous_prefecture SP ,tb_commune C ,tb_localite L ,prejudicemateriel PREJMAT ,infogenerale INF ,prejudicemoraux PREJMo WHERE V.matricule = A.id AND A.id = D.id AND D.id = SP.id AND SP.id = C.id AND C.id = L.id AND L.id = PREJMAT.id_prejMat AND PREJMAT.id_prejMat = INF.id_infoG AND INF.id_infoG = PREJMo.id_prejM $critere GROUP BY V.matricule "; // Le temps des tests : echo "<pre><b>critères :</b><br>"; print_r($critere); echo "</pre>"; echo "<pre><br> <b>La requête est :</b><br> ".$sql."</pre>"; $requete = mysql_query($sql,$cnx) or die( "ERREUR MYSQL numéro: ".mysql_errno()."<br>Type de cette erreur: ".mysql_error()."<br>\n" ); $n = mysql_num_rows($requete ); echo "<br>Nombre de lignes retournées par la requête :".$n;
AND INF.id_infoG = PREJMo.id_prejM
AND $critere
GROUP BY V.matricule