8797 sujets

Développement web côté serveur, CMS

Bonjour a tous,

J'ai crée une base de donnée pour l'entretien des machines de mon parc.

et j'ai fait une page php pour effectuer mes recherches plus facilement.

Cette page permet de faire des recherches sur plusieurs plan et en particulier sur des symptomes qui ont engagé une intervention.

Mon script fonctionne mais que sur un seul mot clé dans ma recherche sur les symptomes et je souhaiterais pouvoir affiner mes recherches en permettant plusieurs mots clés dans la case symptomes mais j'avoue que la ca dépasse mes capacités en php.

Je viens donc vers vous, vous demander de l'aide.

Voci mon code :
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><body>
<!-- Mise en place du formulaire de recherche -->
<form method="post">
<p>Rechercher par :</p><br/>
Machine : <input type="text" name="Machine" /> -
Utilisateur : <input type="text" name="Utilisateur" /> -
Lieu : <input type="text" name="Lieu" /> -
Symptômes : <input type="text" name="Symptomes" />
<br/><input type="submit" value="Chercher" />
</form>
<center><table width="981" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="62"><div align="center">Date</div></td>
    <td width="62"><div align="center">Lieu</div></td>
    <td width="71"><div align="center">Machine</div></td>
    <td width="73"><div align="center">Utilisateur</div></td>
    <td width="80"><div align="center">Symptômes</div></td>
    <td width="86"><div align="center">Intervention</div></td>
 </tr>
<?php
//récupération des variables
$Machine=$_POST['Machine'];
$Utilisateur=$_POST['Utilisateur'];
$Lieu=$_POST['Lieu'];
$Symptomes=$_POST['Symptomes'];
//Requêtes
mysql_connect("localhost", "root", "") or die ("Pas de connexion à la base de données"); // Connexion à MySQL
mysql_select_db("Entretien") or die ("Pas de connexion à la base"); // Sélection de la base coursphp
// Si seul Machine est rempli
if ((!empty($Machine)) and (empty($Utilisateur)) and (empty($Lieu)) and (empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Machine`='$Machine'"); // Requête SQL
}
//Si seul Utilisateur est rempli
if ((empty($Machine)) and (!empty($Utilisateur)) and (empty($Lieu)) and (empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Utilisateur`='$Utilisateur'"); // Requête SQL
}
//Si seul Lieu est rempli
if ((empty($Machine)) and (empty($Utilisateur)) and (!empty($Lieu)) and (empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Lieu`='$Lieu'"); // Requête SQL
}
//Si seul Symptome est rempli ***************************************************************************************
if ((empty($Machine)) and (empty($Utilisateur)) and (empty($Lieu)) and (!empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL
}
//****************************************************************************************************************
//Si Machine et Utilisateur sont rempli
if ((!empty($Machine)) and (!empty($Utilisateur)) and (empty($Lieu)) and (empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Machine`='$Machine' and `Utilisateur`='$Utilisateur'"); // Requête SQL
}
//Si Machine, Utilisateur e t Lieu sont rempli
if ((!empty($Machine)) and (!empty($Utilisateur)) and (!empty($Lieu)) and (empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Machine`='$Machine' and `Utilisateur`='$Utilisateur' and `Lieu`='$Lieu'"); // Requête SQL
}
// Si tous les champs sont remplis
if ((!empty($Machine)) and (!empty($Utilisateur)) and (!empty($Lieu)) and (!empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Machine`='$Machine' and `Utilisateur`='$Utilisateur' and `Lieu`='$Lieu' and `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL
}
//*******************************************************************************************
//Si Utilisateur et Lieu sont rempli
if ((empty($Machine)) and (!empty($Utilisateur)) and (!empty($Lieu)) and (empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Utilisateur`='$Utilisateur' and `Lieu`='$Lieu'"); // Requête SQL
}
//Si utilisateur et Symptomes sont rempli
if ((empty($Machine)) and (!empty($Utilisateur)) and (empty($Lieu)) and (!empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Utilisateur`='$Utilisateur'and `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL
}
//Si Lieu et Symptomes sont rempli
if ((empty($Machine)) and (empty($Utilisateur)) and (!empty($Lieu)) and (!empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Lieu`='$lieu' and `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL
}
//Si Machine et lieu sont rempli
if ((!empty($Machine )) and (empty($Utilisateur)) and (!empty($Lieu)) and (empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Machine`='$Machine' and `Lieu`='$Lieu'"); // Requête SQL
}
//Si Machine et Symptomes sont rempli
if ((!empty($Machine)) and (empty($Utilisateur)) and (empty($Lieu)) and (!empty($Symptomes)))
{
 $reponse = mysql_query("SELECT * FROM intervention WHERE `Machine`='$Machine' and `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL
}
// On fait une boucle pour lister tout ce que contient la table :
 
while ($donnees = mysql_fetch_array($reponse) )
{
?>
  <tr>
    <td><center><strong><?php echo $donnees['Date']; ?></strong></center></td>
    <td><center><strong><?php echo $donnees['Lieu']; ?></strong></center></td>
    <td><center><strong><?php echo $donnees['Machine']; ?></strong></center></td>
    <td><center><strong><?php echo $donnees['Utilisateur']; ?></strong></center></td>
    <td><center><strong><?php echo $donnees['Symptomes']; ?></strong></center></td>
    <td><center><strong><?php echo $donnees['Intervention']; ?></strong></center></td>
   </tr>
<?php
}
 
mysql_close(); // Déconnexion de MySQL
?>
</table></center>
 


Si vous pouvez me donner une piste, un lien, une aide, je suis preneur de tout ce qui peut me faire avancer.

Merci par avance

Lonewolf
Modifié par lonewolf (04 Oct 2008 - 17:16)
C'est bon, j'ai trouvé la solution.

C'est de rajouter ceci dans le code :

$Symptomes = str_replace(" ", "%' AND Symptomes LIKE '%", $Symptomes);


Le code final donne donc :
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html><body>

<!-- Mise en place du formulaire de recherche -->

<form method="post">

<p>Rechercher par :</p><br/>

Machine : <input type="text" name="Machine" /> -

Utilisateur : <input type="text" name="Utilisateur" /> -

Lieu : <input type="text" name="Lieu" /> -

Symptômes : <input type="text" name="Symptomes" />

<br/><input type="submit" value="Chercher" />

</form>

<center><table width="981" border="1" cellspacing="0" cellpadding="0">

  <tr>

    <td width="62"><div align="center">Date</div></td>

    <td width="62"><div align="center">Lieu</div></td>

    <td width="71"><div align="center">Machine</div></td>

    <td width="73"><div align="center">Utilisateur</div></td>

    <td width="80"><div align="center">Symptômes</div></td>

    <td width="86"><div align="center">Intervention</div></td>

 </tr>

<?php

//récupération des variables

$Machine=$_POST['Machine'];

$Utilisateur=$_POST['Utilisateur'];

$Lieu=$_POST['Lieu'];

$Symptomes=$_POST['Symptomes'];

$Symptomes = str_replace(" ", "%' AND Symptomes LIKE '%", $Symptomes);


//Requêtes

mysql_connect("localhost", "root", "") or die ("Pas de connexion à la base de données"); // Connexion à MySQL

mysql_select_db("entretien") or die ("Pas de connexion à la base"); // Sélection de la base coursphp

// Si seul Machine est rempli

if ((!empty($Machine)) and (empty($Utilisateur)) and (empty($Lieu)) and (empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Machine`='$Machine'"); // Requête SQL

}

//Si seul Utilisateur est rempli

if ((empty($Machine)) and (!empty($Utilisateur)) and (empty($Lieu)) and (empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Utilisateur`='$Utilisateur'"); // Requête SQL

}

//Si seul Lieu est rempli

if ((empty($Machine)) and (empty($Utilisateur)) and (!empty($Lieu)) and (empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Lieu`='$Lieu'"); // Requête SQL

}

//Si seul Symptome est rempli ***************************************************************************************

if ((empty($Machine)) and (empty($Utilisateur)) and (empty($Lieu)) and (!empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL

}

//****************************************************************************************************************

//Si Machine et Utilisateur sont rempli

if ((!empty($Machine)) and (!empty($Utilisateur)) and (empty($Lieu)) and (empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Machine`='$Machine' and `Utilisateur`='$Utilisateur'"); // Requête SQL

}

//Si Machine, Utilisateur e t Lieu sont rempli

if ((!empty($Machine)) and (!empty($Utilisateur)) and (!empty($Lieu)) and (empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Machine`='$Machine' and `Utilisateur`='$Utilisateur' and `Lieu`='$Lieu'"); // Requête SQL

}

// Si tous les champs sont remplis

if ((!empty($Machine)) and (!empty($Utilisateur)) and (!empty($Lieu)) and (!empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Machine`='$Machine' and `Utilisateur`='$Utilisateur' and `Lieu`='$Lieu' and `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL

}

//*******************************************************************************************

//Si Utilisateur et Lieu sont rempli

if ((empty($Machine)) and (!empty($Utilisateur)) and (!empty($Lieu)) and (empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Utilisateur`='$Utilisateur' and `Lieu`='$Lieu'"); // Requête SQL

}

//Si utilisateur et Symptomes sont rempli

if ((empty($Machine)) and (!empty($Utilisateur)) and (empty($Lieu)) and (!empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Utilisateur`='$Utilisateur'and `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL

}

//Si Lieu et Symptomes sont rempli

if ((empty($Machine)) and (empty($Utilisateur)) and (!empty($Lieu)) and (!empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Lieu`='$Lieu' and `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL

}

//Si Machine et lieu sont rempli

if ((!empty($Machine )) and (empty($Utilisateur)) and (!empty($Lieu)) and (empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Machine`='$Machine' and `Lieu`='$Lieu'"); // Requête SQL

}

//Si Machine et Symptomes sont rempli

if ((!empty($Machine)) and (empty($Utilisateur)) and (empty($Lieu)) and (!empty($Symptomes)))

{

 $reponse = mysql_query("SELECT * FROM astuces WHERE `Machine`='$Machine' and `Symptomes` LIKE '%$Symptomes%'"); // Requête SQL

}

// On fait une boucle pour lister tout ce que contient la table :
//***********************************************************************************************************************
if ($reponse)
{
//*************************************************************************************************************************
while ($donnees = mysql_fetch_array($reponse))

{

?>

  <tr>

    <td><center><strong><?php echo $donnees['Date']; ?></strong></center></td>

    <td><center><strong><?php echo $donnees['Lieu']; ?></strong></center></td>

    <td><center><strong><?php echo $donnees['Machine']; ?></strong></center></td>

    <td><center><strong><?php echo $donnees['Utilisateur']; ?></strong></center></td>

    <td><center><strong><?php echo $donnees['Symptomes']; ?></strong></center></td>

    <td><center><strong><?php echo $donnees['Intervention']; ?></strong></center></td>

   </tr>

<?php

}



mysql_close(); // Déconnexion de MySQL
//****************************************************************************************************
}
else
{
echo 'Veuillez remplir au moins un champs !!!';
}
//****************************************************************************************************
?>

</table></center>


merci a tous

Amicalement

Lonewolf