Bonjour à tous,
j'ai cherché une solution sur le net mais je ne trouve pas la solution. Voici mon problème. D'abord, je précise que je suis débutante en php.
Sur mon site de petites annonces, j'ai créer un espace de recherche multicritères. Sur la page par défaut, toutes les annonces apparaissent sur plusieurs pages
Ensuite, si on fait une recherche par département, on obtient les résultats sur plusieurs pages.
Pour la 1ère page, pas de problème. Mais quand je clique sur la 2e ou la dernière, les annonces qui s'affichent ne tiennent plus compte des critères de tri.
La 2 page m'affiche donc les résultats de la 2e page que j'avais avant le tri. Et si je reclique sur précédent, c'est la 1ère page avant tri qui s'affiche...
Le code que j'ai utilisé est issu d'un tuto que j'avais trouvé sur le Net. j'espère que vous pourrez vite m'aider car mon site est consulté tous les jours et ca doit être très pénible pour les internautes.
Voici le code :
<?php
$currentPage = $_SERVER["PHP_SELF"];
$SSAdv_colors1 = array("#40BAC4","#A600A6");
$SSAdv_k1 = 0;
$SSAdv_m1 = 0;
$SSAdv_change_every1 = 1;
function Verif_magicquotes ($chaine)
{
if (get_magic_quotes_gpc()) $chaine = stripslashes($chaine);
return $chaine;
}
// Initialisation du message de rponse
$message = null;
include('admin/connexion.php');
$query_departement = "SELECT * FROM departement ORDER BY iddpt ASC";
$departement = mysql_query($query_departement, $connection) or die(mysql_error());
$row_departement = mysql_fetch_assoc($departement);
$totalRows_departement = mysql_num_rows($departement);
$categorie = (isset($_POST['categorie']) && trim($_POST['categorie']) != '')? Verif_magicquotes($_POST['categorie']) : null;
$ville = (isset($_POST['membre_ville']) && trim($_POST['membre_ville']) != '')? Verif_magicquotes($_POST['membre_ville']) : null;
$dpt = (isset($_POST['membre_dpt']) && trim($_POST['membre_dpt']) != '')? Verif_magicquotes($_POST['membre_dpt']) : null;
$numero = (isset($_POST['numero']) && trim($_POST['numero']) != '')? Verif_magicquotes($_POST['numero']) : null;
$maxRows_recherche = 20;
if (isset($_GET['pageNum_recherche'])) {
$pageNum_recherche = $_GET['pageNum_recherche'];
}
$startRow_recherche = $pageNum_recherche * $maxRows_recherche;
$query_recherche = "SELECT * FROM annonces WHERE membre_ville LIKE '%$ville%' AND membre_dpt LIKE '%$dpt%' AND categorie LIKE '%$categorie%' AND numero LIKE '%$numero%' ORDER BY numero DESC";
$query_limit_recherche = sprintf("%s LIMIT %d, %d", $query_recherche, $startRow_recherche, $maxRows_recherche);
$recherche = mysql_query($query_limit_recherche, $connection) or die(mysql_error());
$row_recherche = mysql_fetch_assoc($recherche);
if (isset($_GET['totalRows_recherche'])) {
$totalRows_recherche = $_GET['totalRows_recherche'];
} else {
$all_recherche = mysql_query($query_recherche);
$totalRows_recherche = mysql_num_rows($all_recherche);
}
$totalPages_recherche = ceil($totalRows_recherche/$maxRows_recherche)-1;
$queryString_recherche = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_recherche") == false &&
stristr($param, "totalRows_recherche") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_recherche = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_recherche = sprintf("&totalRows_recherche=%d%s", $totalRows_recherche, $queryString_recherche);
?>
<table width="93%" height="80" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="207" valign="bottom"><div align="center" class="Style37">
<div align="center" class="Style56">Vous recherchez : </div>
</div></td>
<td width="188" valign="bottom"><div align="center" class="Style37">
<div align="center" class="Style56">Votre département : </div>
</div></td>
<td width="197" height="25" valign="bottom"><div align="center" class="Style37">
<div align="center" class="Style56">Votre ville (facultatif) :</div>
</div></td>
</tr>
<tr>
<td valign="bottom"><select name="categorie" class="Style37" id="categorie">
<option value="Parent">Des enfants à garder</option>
<option value="Babysitter">Une babysitter</option>
<option value="Nounou">Une nounou</option>
<option value="Assistante maternelle agréée">Une assistante maternelle agréée</option>
<option value="Aide aux nouvelles mamans">Une aide durant les premiers jours</option>
<option value="Soutien scolaire">Du soutien scolaire</option>
<?php do { ?>
<?php
} while ($row_categorie = mysql_fetch_assoc($categorie));
$rows = mysql_num_rows($categorie);
if($rows > 0) {
mysql_data_seek($categorie, 0);
$row_categorie = mysql_fetch_assoc($categorie);
}
?>
</select> </td>
<td valign="bottom" class="Style37"><select name="membre_dpt" class="Style37" id="membre_dpt">
<?php
do {
?>
<option value="<?php echo $row_departement['dpt']?>"><?php echo $row_departement['numdpt']; ?>-<?php echo $row_departement['dpt']?></option>
<?php
} while ($row_departement = mysql_fetch_assoc($departement));
$rows = mysql_num_rows($departement);
if($rows > 0) {
mysql_data_seek($departement, 0);
$row_departement = mysql_fetch_assoc($departement);
}
?>
</select> </td>
<td height="30" valign="bottom"><div align="center">
<input name="membre_ville" type="text" class="Style37" id="membre_ville" size="22" />
</div></td>
</tr>
<tr>
<td height="35" colspan="3" valign="bottom"><input type="submit" name="Submit" value="Lancer la recherche" /></td>
</tr>
</table>
</div>
</form>
<td colspan="13" valign="top"><div align="center" class="Style23">
<p align="center" class="Style21 Style42 Style50 Style58"><?php echo $totalRows_recherche ?> annonces correspondent à votre recherche :</p>
</div>
<table width="580" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#A600A6">
<tr bgcolor="#FFFFFF">
<tr>
<td class="Style32 Style42 Style45" height="25" width="35"><div align="center" class="Style59">N°</div></td>
<td class="Style32 Style42 Style45" height="25" width="98"> <div align="center" class="Style59">Disponibilité</div></td>
<td class="Style32 Style42 Style45" height="25" width="200" ><div align="center" class="Style59">Titre</div></td>
<td class="Style32 Style42 Style45" height="25"width="180" ><div align="center" class="Style59">Ville</div></td>
<td class="Style32 Style42 Style45" height="25"width="" ><div align="center" class="Style59"><strong>Détails</strong></div></td>
</tr>
</table> <?php do { ?>
<?php if ($totalRows_recherche > 0) { // Show if recordset not empty ?>
<div align="center"></div> <table width="580" border="0" align="center" cellpadding="4" cellspacing="1">
<tr bgcolor="
<?php
if($SSAdv_m1%$SSAdv_change_every1==0 && $SSAdv_m1>0){
$SSAdv_k1++;
}
print $SSAdv_colors1[$SSAdv_k1%count($SSAdv_colors1)];
$SSAdv_m1++;
?>">
<td width="30" align="left" valign="middle" class="53 Style64 Style56 Style75"><?php $idan=$row_recherche['numero'];echo $idan; ?> </td>
<td width="90" align="center" valign="middle" class="Style45 Style42 Style32"><span class="Style47 Style62"><?php echo $row_recherche['dispo']; ?></span></td>
<td width="193" align="center" valign="middle" class="Style45 Style42 Style32"><span class="Style62"><?php echo $row_recherche['titre']; ?></span></td>
<td width="173" align="center" valign="middle" class="Style45 Style42 Style32"><span class="Style47 Style62"><?php echo $row_recherche['membre_ville']; ?></span></td>
<div align="center">
</div>
<td width="" align="center" valign="middle"><div align="center" class="Style53"><a href="file:///C|/Documents%20and%20Settings/Audrey/Mes%20documents/DOMITEAM/Site%20Internet/transfert%20final/voirannonce.php?no=<?php echo $row_recherche['numero']; ?>" target="_blank" class="Style2" onclick="MM_openBrWindow('voirannonce.php?no=<?php echo $row_recherche['numero']; ?>','voirannonce','width=500,height=480')"><img src="Visuels/detail_annonce.jpg" width="12" height="13" border="0"></a></div></td>
</tr>
</table> <?php } // Show if recordset not empty ?>
<?php } while ($row_recherche = mysql_fetch_assoc($recherche)); ?>
<p align="center">
<table border="0" width="50%" align="center">
<!--DWLayoutTable-->
<tr>
<td width="23%" height="50" align="center" valign="top" class="nouveau2"><?php if ($pageNum_recherche > 0) { // Show if not first page ?>
<span class="Style37"><span class="Style46"><span class="Style69 Style31 Style56"><strong><a href="<?php printf("%s?pageNum_recherche=%d%s", $currentPage, 0, $queryString_recherche); ?>">Premier</a></strong></span></span><a href="<?php printf("%s?pageNum_recherche=%d%s", $currentPage, 0, $queryString_recherche); ?>"> <img src="Visuels/First.gif" width="18" height="13" /></a>
<?php } // Show if not first page ?>
<td width="76" align="center" valign="top" class="Style69 Style56 nouveau2"><strong>
<?php if ($pageNum_recherche > 0) { // Show if not first page ?>
<span class="Style37"><span class="Style46"><span class="Style31"><a href="<?php printf("%s?pageNum_recherche=%d%s", $currentPage, max(0, $pageNum_recherche - 1), $queryString_recherche); ?>">Précédent <a href="<?php printf("%s?pageNum_recherche=%d%s", $currentPage, max(0, $pageNum_recherche - 1), $queryString_recherche); ?>"><img src="Visuels/Previous.gif" width="14" height="13" /></a>
<?php } // Show if not first page ?>
</strong></td>
<td width="1"> </td>
<td width="52" align="center" valign="top" class="nouveau2 Style56 Style68"><?php if ($pageNum_recherche < $totalPages_recherche) { // Show if not last page ?>
<span class="Style37"><span class="Style46"><span class="Style31"><a href="<?php printf("%s?pageNum_recherche=%d%s", $currentPage, min($totalPages_recherche, $pageNum_recherche + 1), $queryString_recherche); ?>">Suivant <a href="<?php printf("%s?pageNum_recherche=%d%s", $currentPage, min($totalPages_recherche, $pageNum_recherche + 1), $queryString_recherche); ?>"><img src="Visuels/Next.gif" width="14" height="13" align="middle" /></a>
<?php } // Show if not last page ?>
<td width="6"> </td>
<td width="23%" align="center" valign="top" class="Style69 Style56 nouveau2"><strong>
<?php if ($pageNum_recherche < $totalPages_recherche) { // Show if not last page ?>
<span class="Style37"><span class="Style46"><span class="Style31"><a href="<?php printf("%s?pageNum_recherche=%d%s", $currentPage, $totalPages_recherche, $queryString_recherche); ?>">Dernier <a href="<?php printf("%s?pageNum_recherche=%d%s", $currentPage, $totalPages_recherche, $queryString_recherche); ?>"><img src="Visuels/Last.gif" width="18" height="13" /></a>
<?php } // Show if not last page ?>
</strong>
<td width="11"></td>
</tr>
</table></td>
<td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>