onjour à tous,
Je sollicite votre aide pour un projet sur lequel je travaille depuis un certain temps...sans succès !
Le "Cahier des charges" :
Je souhaiterais créer un formulaire de recherche multi-critères afin de rechercher des motos plus facilement à partir de critères. Les champs du formulaire (sous forme de cases à cocher) correspondraient aux caractéristiques des différents critères.
Le formulaire comporterait les champs suivants :
- Marque (choix possibles : Beta, Derbi, Yamaha)
- Couleur (choix possibles : Noir, Rouge, Bleu, Blanc, Orange, Vert)
- Kilometrage (0 à 1000km, 1000 à 10 000km, 10 000 à 15 000km, 15 000 à 20 000km)
- Année (choix possibles : 2003, 2004, 2005, 2006, 2007, 2008, 2009)
- Distance (choix possibles : -50km, 50 à 60km, 60 à 75km, 75 à 100km, +100km)
- Note (choix possibles : 1, 2, 3, 4, 5)
- Frais supplementaires (choix possibles : 0, 1, 2, 3)
- Prix (choix possibles : -1 000 ¤, 1 000 à 1 200 ¤, 1 200 à 1 500 ¤, 1 500 à 1 700 ¤, +1 700 ¤)
Tous ne doivent pas être forcément renseignés.
En résumé, j'aimerai avir quelque chose qui ressemble à
ce systeme (le cadre "Affiner votre recherche" ainsi que les résultats bien évidement).
<taille valeur="gros"><souligne><gras>Ma base de données :</gras></souligne></taille>
Voici un screenshot de ma base de données :
Mon formulaire :
Code HTML :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Rechercher une moto</title>
<link rel="stylesheet" media="screen" type="text/css" title="css" href="css.css" />
</head>
<body>
<form method="post" action="choix.php" id=criteres>
<p class="titre">Chercher une moto :</p>
<div id="Marque_Annee">
<p>
<span class="sous-titre">Marque :</span><br />
<input type="checkbox" name="beta" id="beta" tabindex="10" /> <label for="beta">Beta</label><br />
<input type="checkbox" name="derbi" id="derbi" tabindex="20" /> <label for="derbi">Derbi</label><br />
<input type="checkbox" name="yamaha" id="yamaha" tabindex="30" /> <label for="yamaha">Yamaha</label><br />
</p>
<p>
<span class="sous-titre">Année :</span><br />
<input type="checkbox" name="2003" id="2003" tabindex="40" /> <label for="2003">2003</label><br />
<input type="checkbox" name="2004" id="2004" tabindex="50" /> <label for="2004">2004</label><br />
<input type="checkbox" name="2005" id="2005" tabindex="60" /> <label for="2005">2005</label><br />
<input type="checkbox" name="2006" id="2006" tabindex="70" /> <label for="2006">2006</label><br />
<input type="checkbox" name="2007" id="2007" tabindex="80" /> <label for="2007">2007</label><br />
<input type="checkbox" name="2008" id="2008" tabindex="90" /> <label for="2008">2008</label><br />
<input type="checkbox" name="2009" id="2009" tabindex="100" /> <label for="2009">2009</label><br />
</p></div>
<div id="Prix_Note">
<p>
<span class="sous-titre">Prix :</span><br />
<input type="checkbox" name="-1000" id="-1000" tabindex="110" /> <label for="-1000">-1 000 ¤</label><br />
<input type="checkbox" name="1000_a_1200" id="1000_a_1200" tabindex="120" /> <label for="1000_a_1200">1 000 ¤ à 1 200 ¤</label><br />
<input type="checkbox" name="1200_a_1500" id="1200_a_1500" tabindex="130" /> <label for="1200_a_1500">1 200 ¤ à 1 500 ¤</label><br />
<input type="checkbox" name="1500_a_1700" id="1500_a_1700" tabindex="140" /> <label for="1500_a_1700">1 500 ¤ à 1 700 ¤</label><br />
<input type="checkbox" name="+1700" id="+1700" tabindex="150" /> <label for="+1700">+1 700 ¤</label><br />
</p>
<p>
<span class="sous-titre">Note :</span><br />
<input type="checkbox" name="1" id="1" tabindex="160" /> <label for="1">1</label><br />
<input type="checkbox" name="2" id="2" tabindex="170" /> <label for="2">2</label><br />
<input type="checkbox" name="3" id="3" tabindex="180" /> <label for="3">3</label><br />
<input type="checkbox" name="4" id="4" tabindex="190" /> <label for="4">4</label><br />
<input type="checkbox" name="5" id="5" tabindex="200" /> <label for="5">5</label><br />
</p></div>
<div id="Couleur_Kilometrage">
<p>
<span class="sous-titre">Couleur :</span><br />
<input type="checkbox" name="noir" id="noir" tabindex="210" /> <label for="noir">Noir</label><br />
<input type="checkbox" name="rouge" id="rouge" tabindex="220" /> <label for="rouge">Rouge</label><br />
<input type="checkbox" name="bleu" id="bleu" tabindex="230" /> <label for="bleu">Bleu</label><br />
<input type="checkbox" name="blanc" id="blanc" tabindex="240" /> <label for="blanc">Blanc</label><br />
<input type="checkbox" name="vert" id="vert" tabindex="250" /> <label for="vert">Vert</label><br />
<input type="checkbox" name="orange" id="orange" tabindex="260" /> <label for="orange">Orange</label><br />
</p>
<p>
<span class="sous-titre">Kilométrage :</span><br />
<input type="checkbox" name="0_a_1000" id="0_a_1000" tabindex="270" /> <label for="0_a_1000">0 à 1 000 KM</label><br />
<input type="checkbox" name="1000_a_10000" id="1000_a_10000" tabindex="280" /> <label for="1000_a_10000">1 000 à 10 000 KM</label><br />
<input type="checkbox" name="10000_a_15000" id="10000_a_15000" tabindex="290" /> <label for="10000_a_15000">10 000 à 15 000 KM</label><br />
<input type="checkbox" name="15000_a_20000" id="15000_a_20000" tabindex="300" /> <label for="15000_a_20000">15 000 à 20 000 KM</label><br />
</p></div>
<div id="Distance_Frais">
<p>
<span class="sous-titre">Distance :</span><br />
<input type="checkbox" name="-50" id="-50" tabindex="310" /> <label for="-50">-50 KM</label><br />
<input type="checkbox" name="50_a_60" id="50_a_60" tabindex="320" /> <label for="50_a_60">50 KM à 60 KM</label><br />
<input type="checkbox" name="60_a_75" id="60_a_75" tabindex="330" /> <label for="60_a_75">60 KM à 75 KM</label><br />
<input type="checkbox" name="75_à_100" id="75_à_100" tabindex="340" /> <label for="75_à_100">75 KM à 100 KM</label><br />
<input type="checkbox" name="+100" id="+100" tabindex="350" /> <label for="+100">+100 KM</label><br />
</p>
<p>
<span class="sous-titre">Frais Supplementaires :</span><br />
<input type="checkbox" name="0" id="0" tabindex="360" /> <label for="0">0</label><br />
<input type="checkbox" name="1" id="1" tabindex="370" /> <label for="1">1</label><br />
<input type="checkbox" name="2" id="2" tabindex="380" /> <label for="2">2</label><br />
<input type="checkbox" name="3" id="3" tabindex="390" /> <label for="3">3</label><br />
</p></div>
<div id="boutons">
<p>
<input type="submit" value="Chercher" /> <input type="reset" />
</p>
</div>
</form>
<div id="resultat">
<!-- ICI LE CODE PHP -->
</div>
</body>
</html>
Le Code PHP :
C'est cette partie du code qui me pose problème...
Je ne vois pas comment faire pour que, par exemple, si beta et 2003 sont cocher, n'afficher que les betas de 2003, si yamaha, bleu, 2004 et -1 000 ¤ sont cocher, n'aficher que les Yamaha bleu de 2004 à moins de 1 000 ¤.
Je proposerais bien ça mais le problème est que si on coche par exemple derbi, sa affiche toutes les derbi, mais si on coche derbi ET 2003, sa n'affiche que les derbi :
Code PHP :
<?php
if ($_POST['beta'] == "on") // Debut
{
try
{
$bdd = new PDO('mysql:host=localhost;dbname=motos', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM liste WHERE marque=\'beta\'');
while ($donnees = $reponse->fetch())
{
?>
<p>
<strong>Marque</strong> : <?php echo $donnees['marque']; ?><br />
<strong>Couleur</strong> : <?php echo $donnees['couleur']; ?><br />
<strong>Kilométrage</strong> : <?php echo $donnees['kilometrage']; ?><br />
<strong>Année</strong> : <?php echo $donnees['annee']; ?><br />
<strong>Distance</strong> : <?php echo $donnees['lieux']; ?><br />
<strong>Note</strong> : <?php echo $donnees['note']; ?><br />
<strong>Frais supplémentaires</strong> : <?php echo $donnees['fraissup']; ?><br />
<strong>Prix</strong> : <?php echo $donnees['prix']; ?><br />
</p>
<?php
}
$reponse->closeCursor();
} // Fin
elseif ($_POST['derbi'] == "on") // Debut
{
try
{
$bdd = new PDO('mysql:host=localhost;dbname=motos', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM liste WHERE marque=\'derbi\'');
while ($donnees = $reponse->fetch())
{
?>
<p>
<strong>Marque</strong> : <?php echo $donnees['marque']; ?><br />
<strong>Couleur</strong> : <?php echo $donnees['couleur']; ?><br />
<strong>Kilométrage</strong> : <?php echo $donnees['kilometrage']; ?><br />
<strong>Année</strong> : <?php echo $donnees['annee']; ?><br />
<strong>Distance</strong> : <?php echo $donnees['lieux']; ?><br />
<strong>Note</strong> : <?php echo $donnees['note']; ?><br />
<strong>Frais supplémentaires</strong> : <?php echo $donnees['fraissup']; ?><br />
<strong>Prix</strong> : <?php echo $donnees['prix']; ?><br />
</p>
<?php
}
$reponse->closeCursor();
} // Fin
elseif ($_POST['yamaha'] == "on") // Debut
{
try
{
$bdd = new PDO('mysql:host=localhost;dbname=motos', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM liste WHERE marque=\'yamaha\'');
while ($donnees = $reponse->fetch())
{
?>
<p>
<strong>Marque</strong> : <?php echo $donnees['marque']; ?><br />
<strong>Couleur</strong> : <?php echo $donnees['couleur']; ?><br />
<strong>Kilométrage</strong> : <?php echo $donnees['kilometrage']; ?><br />
<strong>Année</strong> : <?php echo $donnees['annee']; ?><br />
<strong>Distance</strong> : <?php echo $donnees['lieux']; ?><br />
<strong>Note</strong> : <?php echo $donnees['note']; ?><br />
<strong>Frais supplémentaires</strong> : <?php echo $donnees['fraissup']; ?><br />
<strong>Prix</strong> : <?php echo $donnees['prix']; ?><br />
</p>
<?php
}
$reponse->closeCursor();
} // Fin
elseif ($_POST['2003'] == "on") // Debut
{
try
{
$bdd = new PDO('mysql:host=localhost;dbname=motos', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM liste WHERE annee=\'2003\'');
while ($donnees = $reponse->fetch())
{
?>
<p>
<strong>Marque</strong> : <?php echo $donnees['marque']; ?><br />
<strong>Couleur</strong> : <?php echo $donnees['couleur']; ?><br />
<strong>Kilométrage</strong> : <?php echo $donnees['kilometrage']; ?><br />
<strong>Année</strong> : <?php echo $donnees['annee']; ?><br />
<strong>Distance</strong> : <?php echo $donnees['lieux']; ?><br />
<strong>Note</strong> : <?php echo $donnees['note']; ?><br />
<strong>Frais supplémentaires</strong> : <?php echo $donnees['fraissup']; ?><br />
<strong>Prix</strong> : <?php echo $donnees['prix']; ?><br />
</p>
<?php
}
$reponse->closeCursor();
} // Fin
elseif ($_POST['2004'] == "on") // Debut
{
try
{
$bdd = new PDO('mysql:host=localhost;dbname=motos', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM liste WHERE annee=\'2004\'');
while ($donnees = $reponse->fetch())
{
?>
<p>
<strong>Marque</strong> : <?php echo $donnees['marque']; ?><br />
<strong>Couleur</strong> : <?php echo $donnees['couleur']; ?><br />
<strong>Kilométrage</strong> : <?php echo $donnees['kilometrage']; ?><br />
<strong>Année</strong> : <?php echo $donnees['annee']; ?><br />
<strong>Distance</strong> : <?php echo $donnees['lieux']; ?><br />
<strong>Note</strong> : <?php echo $donnees['note']; ?><br />
<strong>Frais supplémentaires</strong> : <?php echo $donnees['fraissup']; ?><br />
<strong>Prix</strong> : <?php echo $donnees['prix']; ?><br />
</p>
<?php
}
$reponse->closeCursor();
} // Fin
else
{
echo "Désolé mais aucunes moto ne correspondent à vos criteres";
}
?>
Merci d'avance à ceux qui voudront bien m'aider à rendre mon formulaire utilisable...
