Recherche multicritère php
Posté : 22 févr. 2011, 11:35
Bonjour,
J'ai un problème, j'ai créer un formulaire en php qui doit me permettre de faire une recherche avec plusieurs critères sur ma base de donnée faite sous phpmyadmin mais j'obtient ce message d'erreur :
Erreur de requete : 'SELECT * FROM donnees WHERE Entreprise LIKE '%PHIPHI%'AND Nom_site LIKE '%BENNEY%'AND Chef_de_projet LIKE '%moi%'AND Type_operation LIKE '%Autres%'
Script:
<form action="recherche.php" method='post'>
<table>
<tr>
<td><select name="ent">
<option value="#">Selectionnez l'Entreprise-</option>
<?php
//Champs entreprise
$sql = 'SELECT DISTINCT Entreprise FROM donnees ORDER BY Entreprise';
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))
{
echo "<option>";
echo $res['Entreprise'];
echo "</option>";
}
echo "</select></td>";
echo "<tr>";
echo "<td>";
echo "<select name='site'>";
echo "<option value='#'>----------------- Selectionnez Site ------------------</option>";
//Champs Nom Site
$sql = 'SELECT DISTINCT Nom_site FROM donnees ORDER BY Nom_site';
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))
{
echo "<option>";
echo $res['Nom_site'];
echo "</option>";
}
echo "</select></td>";
echo "<tr>";
echo "<td>";
echo "<select name='chef'>";
echo "<option value='#'>-----------Selectionnez Chef de projet------------</option>";
//Champs Chef de projet
$sql = 'SELECT DISTINCT Chef_de_projet FROM donnees ORDER BY Chef_de_projet';
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))
{
echo "<option>";
echo $res['Chef_de_projet'];
echo "</option>";
}
echo "</select></td>";
echo "<tr>";
echo "<td>";
echo "<select name='typeop'>";
echo "<option value='#'>--------Type d'opération-------</option>";
//Champs Type d'opération
$sql = 'SELECT DISTINCT Type_operation FROM donnees ORDER BY Type_operation';
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))
{
echo "<option>";
echo $res['Type_operation'];
echo "</option>";
}
echo "</select></td>";
echo "<tr>";
echo "<td><input type='submit' value='Rechercher'></td>";
echo "</tr>";
echo "</table>";
// on teste si les variables du formulaire sont déclarées
if (isset($_POST['ent']) && isset($_POST['site'])&& isset($_POST['chef'])&& isset($_POST['typeop']))
{
// on prépare la requête pour récupérer le numero du propriétaire
$sql = 'SELECT * FROM donnees';
// on lance la requête (mysql_query) et on impose un message d'erreur si la requête ne se passe pas bien (or die)
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
// on libère l'espace mémoire alloué pour cette interrogation de la base
mysql_free_result ($req);
// lancement de la requête
$sql ="'SELECT * FROM donnees WHERE Entreprise LIKE '%".$_POST['ent']."%'AND
Nom_site LIKE '%".$_POST['site']."%'AND Chef_de_projet LIKE '%".$_POST['chef']."%'AND
Type_operation LIKE '%".$_POST['typeop']."%'";
?>
<table border='1'class="tableau">
<tr>
<th>Numero</th>
<th>Non_suivie</th>
<th>Entreprise</th>
<th>Chef_de_projet</th>
<th>Code_NIDT</th>
<th>Nom_site</th>
<th>DR</th>
<th>Type_operation</th>
<th>Date_ADT</th>
<th>Date_recep_lettre_com </th>
<th>Date_apl_livr_politique_achat</th>
<th>Date_visite_inspection_commune </th>
<th>Date_autorisation_ouv_chantier</th>
<th>Necessite_coffret</th>
<th>Date_prevu_MAD</th>
<th>Date_reelle_MAD</th>
<th>Necessite_raccordt_EDF</th>
<th>Date_preu_MEST_EDF</th>
<th>Date_rel_MEST_EDF</th>
<th>Date1_prevision_FN6</th>
<th>Date2_prevision_FN6</th>
<th>Date3_prevision_FN6</th>
<th>Date_prog_recette_site</th>
<th>DATE_FN6_RES_NB</th>
<th>Date_FN6_sans_reserve</th>
<th>Corr_delais_FN6</th>
<th>Com_corr_delais_FN6</th>
<th>Synthese_corr</th>
<th>inhiber</th>
</tr>
<?php
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))/*Elle retourne un tableau avec le nom des champs sélectionnés comme
indice.L'option MYSQL_ASSOC permet de ne générer qu'un tableau associatif */
{
echo "<tr>";
echo "<td>".$res[0]."</td>";
echo "<td>".$res[1]."</td>";
echo "<td>".$res[2]."</td>";
echo "<td>".$res[3]."</td>";
echo "<td>".$res[4]."</td>";
echo "<td>".htmlentities($res[5], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[6]."</td>";
echo "<td>".htmlentities($res[7], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[8], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[9], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[10], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[11], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[12], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[13]."</td>";
echo "<td>".htmlentities($res[14], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[15], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[16]."</td>";
echo "<td>".htmlentities($res[17], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[18], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[19], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[20], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[21], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[22], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[23], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[24], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[25]."</td>";
echo "<td>".htmlentities($res[26], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[27], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[28]."</td>";
echo "</tr>";
}
echo "</table>";
}
echo "</form>";
echo "</div>";
Ma base de donnée:
Numero Non_suivie Entreprise Chef_de_projet Code_NIDT Nom_site DR Type_operation Date_ADT Date_recep_lettre_com Date_apl_livr_politique_achat Date_visite_inspection_commune Date_autorisation_ouv_chantier Necessite_coffret Date_prevu_MAD Date_reelle_MAD Necessite_raccordt_EDF Date_preu_MEST_EDF Date_rel_MEST_EDF Date1_prevision_FN6 Date2_prevision_FN6 Date3_prevision_FN6 Date_prog_recette_site DATE_FN6_RES_NB Date_FN6_sans_reserve Corr_delais_FN6 Com_corr_delais_FN6 Synthese_corr inhiber
Merci de votre aide.
J'ai un problème, j'ai créer un formulaire en php qui doit me permettre de faire une recherche avec plusieurs critères sur ma base de donnée faite sous phpmyadmin mais j'obtient ce message d'erreur :
Erreur de requete : 'SELECT * FROM donnees WHERE Entreprise LIKE '%PHIPHI%'AND Nom_site LIKE '%BENNEY%'AND Chef_de_projet LIKE '%moi%'AND Type_operation LIKE '%Autres%'
Script:
<form action="recherche.php" method='post'>
<table>
<tr>
<td><select name="ent">
<option value="#">Selectionnez l'Entreprise-</option>
<?php
//Champs entreprise
$sql = 'SELECT DISTINCT Entreprise FROM donnees ORDER BY Entreprise';
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))
{
echo "<option>";
echo $res['Entreprise'];
echo "</option>";
}
echo "</select></td>";
echo "<tr>";
echo "<td>";
echo "<select name='site'>";
echo "<option value='#'>----------------- Selectionnez Site ------------------</option>";
//Champs Nom Site
$sql = 'SELECT DISTINCT Nom_site FROM donnees ORDER BY Nom_site';
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))
{
echo "<option>";
echo $res['Nom_site'];
echo "</option>";
}
echo "</select></td>";
echo "<tr>";
echo "<td>";
echo "<select name='chef'>";
echo "<option value='#'>-----------Selectionnez Chef de projet------------</option>";
//Champs Chef de projet
$sql = 'SELECT DISTINCT Chef_de_projet FROM donnees ORDER BY Chef_de_projet';
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))
{
echo "<option>";
echo $res['Chef_de_projet'];
echo "</option>";
}
echo "</select></td>";
echo "<tr>";
echo "<td>";
echo "<select name='typeop'>";
echo "<option value='#'>--------Type d'opération-------</option>";
//Champs Type d'opération
$sql = 'SELECT DISTINCT Type_operation FROM donnees ORDER BY Type_operation';
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))
{
echo "<option>";
echo $res['Type_operation'];
echo "</option>";
}
echo "</select></td>";
echo "<tr>";
echo "<td><input type='submit' value='Rechercher'></td>";
echo "</tr>";
echo "</table>";
// on teste si les variables du formulaire sont déclarées
if (isset($_POST['ent']) && isset($_POST['site'])&& isset($_POST['chef'])&& isset($_POST['typeop']))
{
// on prépare la requête pour récupérer le numero du propriétaire
$sql = 'SELECT * FROM donnees';
// on lance la requête (mysql_query) et on impose un message d'erreur si la requête ne se passe pas bien (or die)
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
// on libère l'espace mémoire alloué pour cette interrogation de la base
mysql_free_result ($req);
// lancement de la requête
$sql ="'SELECT * FROM donnees WHERE Entreprise LIKE '%".$_POST['ent']."%'AND
Nom_site LIKE '%".$_POST['site']."%'AND Chef_de_projet LIKE '%".$_POST['chef']."%'AND
Type_operation LIKE '%".$_POST['typeop']."%'";
?>
<table border='1'class="tableau">
<tr>
<th>Numero</th>
<th>Non_suivie</th>
<th>Entreprise</th>
<th>Chef_de_projet</th>
<th>Code_NIDT</th>
<th>Nom_site</th>
<th>DR</th>
<th>Type_operation</th>
<th>Date_ADT</th>
<th>Date_recep_lettre_com </th>
<th>Date_apl_livr_politique_achat</th>
<th>Date_visite_inspection_commune </th>
<th>Date_autorisation_ouv_chantier</th>
<th>Necessite_coffret</th>
<th>Date_prevu_MAD</th>
<th>Date_reelle_MAD</th>
<th>Necessite_raccordt_EDF</th>
<th>Date_preu_MEST_EDF</th>
<th>Date_rel_MEST_EDF</th>
<th>Date1_prevision_FN6</th>
<th>Date2_prevision_FN6</th>
<th>Date3_prevision_FN6</th>
<th>Date_prog_recette_site</th>
<th>DATE_FN6_RES_NB</th>
<th>Date_FN6_sans_reserve</th>
<th>Corr_delais_FN6</th>
<th>Com_corr_delais_FN6</th>
<th>Synthese_corr</th>
<th>inhiber</th>
</tr>
<?php
$reponse = mysql_query($sql) or die("Erreur de requete : ".$sql);
while ($res = mysql_fetch_array($reponse))/*Elle retourne un tableau avec le nom des champs sélectionnés comme
indice.L'option MYSQL_ASSOC permet de ne générer qu'un tableau associatif */
{
echo "<tr>";
echo "<td>".$res[0]."</td>";
echo "<td>".$res[1]."</td>";
echo "<td>".$res[2]."</td>";
echo "<td>".$res[3]."</td>";
echo "<td>".$res[4]."</td>";
echo "<td>".htmlentities($res[5], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[6]."</td>";
echo "<td>".htmlentities($res[7], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[8], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[9], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[10], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[11], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[12], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[13]."</td>";
echo "<td>".htmlentities($res[14], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[15], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[16]."</td>";
echo "<td>".htmlentities($res[17], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[18], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[19], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[20], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[21], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[22], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[23], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[24], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[25]."</td>";
echo "<td>".htmlentities($res[26], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".htmlentities($res[27], ENT_QUOTES,'UTF-8')."</td>";
echo "<td>".$res[28]."</td>";
echo "</tr>";
}
echo "</table>";
}
echo "</form>";
echo "</div>";
Ma base de donnée:
Numero Non_suivie Entreprise Chef_de_projet Code_NIDT Nom_site DR Type_operation Date_ADT Date_recep_lettre_com Date_apl_livr_politique_achat Date_visite_inspection_commune Date_autorisation_ouv_chantier Necessite_coffret Date_prevu_MAD Date_reelle_MAD Necessite_raccordt_EDF Date_preu_MEST_EDF Date_rel_MEST_EDF Date1_prevision_FN6 Date2_prevision_FN6 Date3_prevision_FN6 Date_prog_recette_site DATE_FN6_RES_NB Date_FN6_sans_reserve Corr_delais_FN6 Com_corr_delais_FN6 Synthese_corr inhiber
Merci de votre aide.