Page 1 sur 1

Filtre de recherche par prix

Posté : 27 févr. 2009, 11:19
par jeromebo
Bonjour, je suis en train de faire un filtre multi-critère, j'ai 4 tables, une table c'est les annonces et les autres sont les critères (ville, type, état ). Donc j'ai fait des menu qui reprennent les informations de ville, type et etat, a ce niveau pas de souci. si je cherche les annonces dans une ville c'est en ordre. Par contre j'ai un souci pour la recherche d'annonce par tranche de prix. Je veux faire un menu du style :
<500
500-1000
1500-2000
>2000

il faudrait qu'il filtre les annonces avec ces critères de prix. Mon problème est qu'il filtre uniquement par tranche et non tout les tranches.
Ou dois-je mettre mes conditions?

mon sql :

Code : Tout sélectionner

$query_rsannonce = sprintf("SELECT * FROM m_annonce WHERE id_type = %s OR id_ville = %s OR id_budget = %s OR id_etat = %s",
mon form :

Code : Tout sélectionner

<form id="rech" name="rech" method="get" action="index.php"> <p>&nbsp;</p> <table width="69%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="102" height="20" class="titre_index"><div align="center">Type</div></td> <td width="124" class="titre_index"><div align="center">Etat</div></td> <td width="121" class="titre_index"><div align="center">Votre budget</div></td> <td width="185" class="titre_index"><div align="center">Localit&eacute;</div></td> <td width="153">&nbsp;</td> </tr> <tr align="center"> <td><label> <select name="type" id="type"> <option value="">Indifférent</option> <?php do { ?> <option value="<?php echo $row_rstype['id_type']?>"><?php echo $row_rstype['type']?></option> <?php } while ($row_rstype = mysql_fetch_assoc($rstype)); $rows = mysql_num_rows($rstype); if($rows > 0) { mysql_data_seek($rstype, 0); $row_rstype = mysql_fetch_assoc($rstype); } ?> </select> </label></td> <td><label> <select name="etat" id="etat"> <option value="">Indifférent</option> <?php do { ?> <option value="<?php echo $row_rsetat['id_etat']?>"><?php echo $row_rsetat['etat']?></option> <?php } while ($row_rsetat = mysql_fetch_assoc($rsetat)); $rows = mysql_num_rows($rsetat); if($rows > 0) { mysql_data_seek($rsetat, 0); $row_rsetat = mysql_fetch_assoc($rsetat); } ?> </select> </label></td> <td><label> <select name="budget" id="budget"> <option value="">Indifférent</option> <?php do { ?> <option value="<?php echo $row_rsbudget['id_budget']?>"><?php echo $row_rsbudget['budget']?></option> <?php } while ($row_rsbudget = mysql_fetch_assoc($rsbudget)); $rows = mysql_num_rows($rsbudget); if($rows > 0) { mysql_data_seek($rsbudget, 0); $row_rsbudget = mysql_fetch_assoc($rsbudget); } ?> </select> </label></td> <td><label> <select name="ville" id="ville"> <option value="">Indifférent</option> <?php do { ?><option value="<?php echo $row_rsville['id_ville']?>"><?php echo $row_rsville['ville']?></option> <?php } while ($row_rsville = mysql_fetch_assoc($rsville)); $rows = mysql_num_rows($rsville); if($rows > 0) { mysql_data_seek($rsville, 0); $row_rsville = mysql_fetch_assoc($rsville); } ?> </select> </label></td> <td><label> <input type="submit" name="submit" id="submit" value="Rechercher" /> </label></td> </tr> <tr align="center"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr align="center"> <td colspan="5"><hr /></td> </tr> </table> <p>&nbsp;</p> <p class="titre">R&eacute;sultats : </p> <?php do { ?> <table width="65%" height="20" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="18%" class="titre_index"><p><?php echo $row_rsannonce['titre']; ?><br /> <span class="text"><?php echo KT_formatDate($row_rsannonce['date']); ?></span></p> </td> <td width="24%" class="text"><?php echo $row_rsannonce['description']; ?></td> <td width="20%" class="text"></td> <td width="3%" class="text">&nbsp;</td> <td width="18%" class="text"></td> <td width="2%" class="text">&nbsp;</td> <td width="15%" class="text"><?php echo $row_rsannonce['prix']; ?>.-</td> </tr> <tr> <td colspan="7" class="titre_index"><hr /></td> </tr> </table> <?php } while ($row_rsannonce = mysql_fetch_assoc($rsannonce)); ?><p>&nbsp;</p> </form>
Merci d'avance de votre aide...

Re: Filtre de recherche par prix

Posté : 27 févr. 2009, 15:36
par Aureusms
mon sql :
Code:
$query_rsannonce = sprintf("SELECT * FROM m_annonce WHERE id_type = %s OR id_ville = %s OR id_budget = %s OR id_etat = %s",
Si tu faisais cela pour essayer :

Code : Tout sélectionner

SELECT * FROM m_annonce WHERE id_type = %s OR id_ville = %s OR id_budget BETWEEN 'min' and 'max' OR id_etat = %s",
plus d'infos : http://dev.mysql.com/doc/refman/5.0/fr/ ... ators.html

filtre

Posté : 02 mars 2009, 16:21
par jeromebo
c'était cela, ca fonctionne parfaitement, merci

j'aurai encore une question, là mes filtre multi critère fonctionne. Au début de chaque picklist, je mets le mot INDIFFERENT, comme cela si il ne veulent pas un certain critère, normalement tout viens afficher.. Par contre, je voudrais que lorsque que toute les pickliste sont noté en tant que INDIFFERENT alors j'affiche toute les annonces.

Dois je faire un nouveau recordset ou puis-je utiliser le meme.

merci d'avance