Triage de produits par SELECT et requête SQL en PHP
Bonjour!
Je suis en train de travailler sur un catalogue de produits et je veux trier mes résultats de rechrche par ordre de prix et alphabétique ASC et DESC.
Est-ce que quelqu'un pourrait m'expliquer pourquoi ça ne fonctionne pas?
Merci!!! :D
J'ai fait ceci :
Appel d'une requête SQL :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
function afficheProduitsRech($champRecherche, $optionSelect) {
$reqProduitsRecherches = "SELECT * FROM mbam_produit WHERE prod_titre LIKE '%$champRecherche%' ORDER BY '$optionSelect'";
$res = mysql_query($reqProduitsRecherches);
$tabResRech = array();
while($enreg = mysql_fetch_assoc($res)) {
$tabResRech[] = $enreg;
}
return $tabResRech;
} |
FICHIER PHP
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
<?php
print('Résultat(s) de recherche avec le(s) mot(s): <b>'.$champRecherche.'</b>');
print('<form name="triageRecherche" method="post">');
print('<select name="triageRecherche">');
print('<option selected value="prod_prix ASC">Prix croissant</option>');
print('<option value="prod_prix DES">Prix décroissant</option>');
print('<option value="prod_titre ASC">Alphabétique croissant</option>');
print('<option value="prod_titre DES">Alphabétique décroissant</option>');
print('</select>');
print('</form">');
$optionSelect = $_POST["triageRecherche"];
$produits = afficheProduitsRech($champRecherche, $optionSelect);
for($i=0; $i<count($produits); $i++) {
$titre = $produits[$i]["prod_titre"];
$prix = $produits[$i]["prod_prix"];
$img = $produits[$i]["prod_image"];
}
?> |