par
pacphil » 02 mars 2012, 21:53
Bonsoir j'ai réalisé avec l'aide d'un ami un moteur de recherche sur plusieurs champs de recherche , le soucis que j'ai que je reste dans la paginations sur les page avant ou précédente dans ma recherche et pas sur une autre suivant les champs que j'ai choisi ?
Et j'ai un problème sur la recherche de ma fourchette de prix entre prix et prix1 une idée aussi
<?php
include("cssstyle/haut.php");
include("sources/config.php");
?>
<br />
<div id="messamain">
<div id="messamenu">
<div id="menu11">
<img src="cssstyle/imdesign/pub1.png" width="150" height="150" border="0" /><br/><br/>
<img src="cssstyle/imdesign/pub1.png" width="150" height="150" border="0" />
</div></div>
<div id="conmessa">
<br />
<table width="600" border="0" align="center">
<tr>
<td>
<table width="100%" border="0">
<tr>
<td bgcolor="#0099CC">
<div align="center" class="messagerie"><b>Résultat de la recherche</b></div>
</td>
</tr>
</table>
<?php
$where = array();
// j'ai considéré que tous ces champs étaient des varchar dans ta base de données
if (isset($_POST['typeb']) && strlen($_POST['typeb'])) {
$where[] = "typeb = '".mysql_real_escape_string($_POST['typeb'])."'";
}
if (isset($_POST['pays']) && strlen($_POST['pays'])) {
$where[] = "pays = '".mysql_real_escape_string($_POST['pays'])."'";
}
if (isset($_POST['province']) && strlen($_POST['province'])) {
$where[] = "province = '".mysql_real_escape_string($_POST['province'])."'";
}
if (isset($_POST['ville']) && strlen($_POST['ville'])) {
$where[] = "ville = '".mysql_real_escape_string($_POST['ville'])."'";
}
if (isset($_POST['vendeur']) && strlen($_POST['vendeur'])) {
$where[] = "vendeur = '".mysql_real_escape_string($_POST['vendeur'])."'";
}
// uniquement les entiers sont acceptés pour les prix
if (isset($_POST['prix']) && isset($_POST['prix1'])
&& ctype_digit($_POST['prix']) && ctype_digit($_POST['prix1']))
{
$where[] = 'prixb BETWEEN '.$_POST['prix'].' AND '.$_POST['prix1'];
}
echo'<table width="100%" bgcolor="#0099FF" class="messagerie" border="0">
<tr>
<td width="10%"><b>N°</b></td>
<td width="20%"><b>Pays</b></td>
<td width="15%"><b>Région</b></td>
<td width="20%"><b>Commune</b></td>
<td width="15%"><b>Type de vente</b></td>
<td width="15%"><b>Prix</b></td>
<td width="5%"><b>Voir</b></td>
</tr></table>';
$tableName="annonce";
$targetpage = "search-val.php";
$limit = 10;
$sqlWhere = (empty($where)) ? null : 'WHERE '.implode(' AND ', $where);
$query = "SELECT COUNT(*) as num FROM $tableName ".$sqlWhere."";
$total_pages = mysql_fetch_array(mysql_query($query));
@$total_pages = $total_pages[num];
$stages = 3;
@$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM $tableName ".$sqlWhere." LIMIT $start,$limit";
$result = mysql_query($query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
while($plus = mysql_fetch_assoc($result))
{
$ida = $plus["idA"];
$ligne = $ida;
//Affichage l'aannonce
echo'<table width="100%" bgcolor=" '. (($ligne++ % 2)?"#C0F3AB":"#ABEF8D") .'">
<tr>
<td width="10%">'.$plus["ref"].'</td>
<td width="20%">'.$plus["pays"].'</td>
<td width="15%">'.$plus["province"].'</td>
<td width="20%">'.$plus["ville"].'</td>
<td width="15%">'.$plus["vendeur"].'</td>
<td width="15%"><font color="#FF0000"><b>'.$plus["prixb"].'</b></font></td>
<td width="5%"><a href="detail_anno.php?detail='.$ida.'"><img src="cssstyle/imdesign/oeil.png" width="30" height="30" border="0" /></a></td>
</tr></table>';
}
echo $paginate;
?>
<?php
echo'</td></tr>
<tr>
<td>
<table width="100%" border="0">
<tr><hr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
<br />
</div>
</div>';
include("cssstyle/bas.php");
?>
Bonsoir j'ai réalisé avec l'aide d'un ami un moteur de recherche sur plusieurs champs de recherche , le soucis que j'ai que je reste dans la paginations sur les page avant ou précédente dans ma recherche et pas sur une autre suivant les champs que j'ai choisi ?
Et j'ai un problème sur la recherche de ma fourchette de prix entre prix et prix1 une idée aussi
[php]<?php
include("cssstyle/haut.php");
include("sources/config.php");
?>
<br />
<div id="messamain">
<div id="messamenu">
<div id="menu11">
<img src="cssstyle/imdesign/pub1.png" width="150" height="150" border="0" /><br/><br/>
<img src="cssstyle/imdesign/pub1.png" width="150" height="150" border="0" />
</div></div>
<div id="conmessa">
<br />
<table width="600" border="0" align="center">
<tr>
<td>
<table width="100%" border="0">
<tr>
<td bgcolor="#0099CC">
<div align="center" class="messagerie"><b>Résultat de la recherche</b></div>
</td>
</tr>
</table>
<?php
$where = array();
// j'ai considéré que tous ces champs étaient des varchar dans ta base de données
if (isset($_POST['typeb']) && strlen($_POST['typeb'])) {
$where[] = "typeb = '".mysql_real_escape_string($_POST['typeb'])."'";
}
if (isset($_POST['pays']) && strlen($_POST['pays'])) {
$where[] = "pays = '".mysql_real_escape_string($_POST['pays'])."'";
}
if (isset($_POST['province']) && strlen($_POST['province'])) {
$where[] = "province = '".mysql_real_escape_string($_POST['province'])."'";
}
if (isset($_POST['ville']) && strlen($_POST['ville'])) {
$where[] = "ville = '".mysql_real_escape_string($_POST['ville'])."'";
}
if (isset($_POST['vendeur']) && strlen($_POST['vendeur'])) {
$where[] = "vendeur = '".mysql_real_escape_string($_POST['vendeur'])."'";
}
// uniquement les entiers sont acceptés pour les prix
if (isset($_POST['prix']) && isset($_POST['prix1'])
&& ctype_digit($_POST['prix']) && ctype_digit($_POST['prix1']))
{
$where[] = 'prixb BETWEEN '.$_POST['prix'].' AND '.$_POST['prix1'];
}
echo'<table width="100%" bgcolor="#0099FF" class="messagerie" border="0">
<tr>
<td width="10%"><b>N°</b></td>
<td width="20%"><b>Pays</b></td>
<td width="15%"><b>Région</b></td>
<td width="20%"><b>Commune</b></td>
<td width="15%"><b>Type de vente</b></td>
<td width="15%"><b>Prix</b></td>
<td width="5%"><b>Voir</b></td>
</tr></table>';
$tableName="annonce";
$targetpage = "search-val.php";
$limit = 10;
$sqlWhere = (empty($where)) ? null : 'WHERE '.implode(' AND ', $where);
$query = "SELECT COUNT(*) as num FROM $tableName ".$sqlWhere."";
$total_pages = mysql_fetch_array(mysql_query($query));
@$total_pages = $total_pages[num];
$stages = 3;
@$page = mysql_escape_string($_GET['page']);
if($page){
$start = ($page - 1) * $limit;
}else{
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM $tableName ".$sqlWhere." LIMIT $start,$limit";
$result = mysql_query($query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1)
{
$paginate .= "<div class='paginate'>";
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
}else{
$paginate.= "<span class='disabled'>previous</span>"; }
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
elseif($lastpage > 5 + ($stages * 2)) // Enough pages to hide a few?
{
// Beginning only hide later pages
if($page < 1 + ($stages * 2))
{
for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// Middle hide some front and some back
elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
$paginate.= "...";
$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";
}
// End only hide early pages
else
{
$paginate.= "<a href='$targetpage?page=1'>1</a>";
$paginate.= "<a href='$targetpage?page=2'>2</a>";
$paginate.= "...";
for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{
$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>next</a>";
}else{
$paginate.= "<span class='disabled'>next</span>";
}
$paginate.= "</div>";
}
while($plus = mysql_fetch_assoc($result))
{
$ida = $plus["idA"];
$ligne = $ida;
//Affichage l'aannonce
echo'<table width="100%" bgcolor=" '. (($ligne++ % 2)?"#C0F3AB":"#ABEF8D") .'">
<tr>
<td width="10%">'.$plus["ref"].'</td>
<td width="20%">'.$plus["pays"].'</td>
<td width="15%">'.$plus["province"].'</td>
<td width="20%">'.$plus["ville"].'</td>
<td width="15%">'.$plus["vendeur"].'</td>
<td width="15%"><font color="#FF0000"><b>'.$plus["prixb"].'</b></font></td>
<td width="5%"><a href="detail_anno.php?detail='.$ida.'"><img src="cssstyle/imdesign/oeil.png" width="30" height="30" border="0" /></a></td>
</tr></table>';
}
echo $paginate;
?>
<?php
echo'</td></tr>
<tr>
<td>
<table width="100%" border="0">
<tr><hr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
<br />
</div>
</div>';
include("cssstyle/bas.php");
?>[/php]