Probleme barre de recherche avec pagination
Posté : 04 juin 2016, 04:28
Bonjour ! j'aimerai bien crée une page de recherche avec Un champ de type text et deux listes deroulantes et une partie pagination une fois le nombre d'article est important. mais pour le moment je suis bloqué dans la partie barre de recherhce car ma recherche me donne juste les resultat pour le champ de type text mais si je selection aussi un elemennt dans la liste deroulante ça me donne rien...
J'ai vraiment besoin de votre aide ...
Voici mon code en question
J'ai vraiment besoin de votre aide ...
Voici mon code en question
<?php
session_start();
require_once 'class.user.php';
$user_home = new USER();
if(!$user_home->is_logged_in())
{
$user_home->redirect('index.php');
}
.....
// DEBU PAGINATION
$bdd = new PDO("mysql:host=127.0.0.1;dbname=dbtest;charset=utf8", "root", "");
$annoncesParPage = 3;
$annoncesTotalesReq = $bdd->query('SELECT annonce_id FROM annonce');
$annoncesTotales = $annoncesTotalesReq->rowCount();
$pagesTotales = ceil($annoncesTotales/$annoncesParPage);
if(isset($_GET['page']) AND !empty($_GET['page']) AND $_GET['page'] > 0 AND $_GET['page'] <= $pagesTotales) {
$_GET['page'] = intval($_GET['page']);
$pageCourante = $_GET['page'];
} else {
$pageCourante = 1;
}
$depart = ($pageCourante-1)*$annoncesParPage;
// FIN PAGINATION
$bdd = new PDO('mysql:host=127.0.0.1;dbname=dbtest;charset=utf8', 'root', '');
$stmt = $bdd->prepare("SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.id_categorie, typecat.* FROM annonce INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie WHERE tbl_users.userID = '".$id_user."' ORDER BY annonce.date_annonce DESC LIMIT ".$depart.','.$annoncesParPage);
$stmt->execute();
//DEBUT BARRE DE RECHERCHE
$select = 'SELECT tbl_users.userID, tbl_users.userType, annonce.*, categorie.*, typecat.*
FROM annonce
INNER JOIN tbl_users ON annonce.user_id = tbl_users.userID
INNER JOIN categorie ON categorie.id_categorie = annonce.categorie_id
INNER JOIN typecat ON typecat.categorie_id = categorie.id_categorie ';
$where = array();
$param = array();
if(isset($_POST['titre'])){
$where[] = 'CONCAT(titre_annonce, commentaire) LIKE :titre';
$param[':titre'] = '%'.$_POST['titre'].'%';
}
if (isset($_POST['cat'])){
$where[] = 'categorie.libele_cat = :cat';
$param[':cat'] = $_POST['cat'];
}
$where = ' WHERE ' . implode(' AND ', $where);
$order = ' ORDER BY annonce.date_annonce DESC'.
$limit = ' LIMIT '.$depart.','.$annoncesParPage;
$stmt = $bdd->prepare($select . $where . $order . $limit);
$stmt->execute(array($param));
//FIN BARRE DE RECHERHCE
?>
<!DOCTYPE html>
<html class="no-js">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $row['userEmail']; ?></title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link href="assets/styles.css" rel="stylesheet" media="screen">
<link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
<script type="text/javascript" src="javascript/script.js"></script>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/DT_bootstrap.js"></script>
</head>
<body>
<div class="container-fluid" style="margin-top:80px;">
....
<div class="search" style="text-align: center;">
<?php
?>
<form method="GET">
<input type="text" name="titre" placeholder="Que recherchez-vous?" style="height: 40px; margin-top: 10px;">
<select style="height: 40px;" name="cat">
<option value="toutes-categories" disabled="disabled" selected="selected">Toutes les catégories</option>
<option value="informatique-et-multimedia" style="" >Informatique et Multimedia</option>
<option value="vehicule" style="" >Véhicules</option>
<option value="immobilier" style="" >Immobilier</option>
<option value="maison-et-jardin" style="" >Pour la maison et Jardin</option>
<option value="habillement-et-bien-etre" style="" >Habillement et Bien Etre</option>
<option value="loisirs-et-divertissement" style="" >Loisirs et Divertissement</option>
<option value="emploi-et-service" style="" >Emploi et Services</option>
<option value="entreprise" style="" >Entreprises</option>
<option value="autres" style="" >Autres</option>
</select>
<select style="height: 40px;" name="ville_ad">
<option disabled="disabled" value="" selected="selected">Toutes les villes</option>
<option value="Chaouia-Ouardigha">Chaouia-Ouardigha</option>
<option value="Doukkala-Abda">Doukkala-Abda</option>
<option value="Fes-Boulemane">Fes Boulemane</option>
<option value="Gharb-Chrarda">Gharb-Chrarda</option>
<option value="Casablanca">Casablanca</option>
<option value="Guelmim-Es-Semara">Guelmim-Es Semara</option>
<option value="Laayoune-Boujdour">Laayoune-Boujdour</option>
<option value="Marrakech">Marrakech</option>
<option value="Meknes">Meknès</option>
<option value="Loriental">L'oriental</option>
<option value="Oued-ed-Dahab-Lagouira">Oued ed Dahab-Lagouira</option>
<option value="Rabat">Rabat</option>
<option value="Sale">Salé</option>
<option value="Souss-Massa-Draa">Souss-Massa-Draa</option>
<option value="Tadla-Azilal">Tadla-Azilal</option>
<option value="Tanger-Tetouan">Tanger-Tetouan</option>
<option value="Taza-Al-Taounate">Taza-Al-Taounate</option>
<option value="Zaer-Zemmour">Zaer-Zemmour</option>
</select>
<button class="btn btn-default" type="submit" style="height: 40px;"><i class="glyphicon glyphicon-search"></i></button>
</form>
</div>
<!-- DEBUT AFFICHAGE RECHERCHE-->
<?php
if($stmt->rowCount() > 0) {
while($row = $stmt->fetch()){
$id_date=$row['date_annonce'];
?>
<table class="table table-striped table-bordered" id="example">
<tr>
<td style="text-align:center; height:150px; width:150px;"><?php if($row['photo_annonce'] != ""): ?>
<a href="viewad.php?ad=<?php echo $row['annonce_id']; ?>"><img src="images/annonces/<?php echo $row['photo_annonce']; ?>" width="100px" height="100px"><br><span>1 Photo</span></a>
<?php else: ?>
<a href="viewad.php?ad=<?php echo $row['annonce_id']; ?>"><img src="images/upimag.png" width="100px" height="100px"><br><span>0 Photo</span></a>
<?php endif; ?>
</td>
<td style="padding-left:10px;">
<a href="viewad.php?ad=<?php echo $row['annonce_id']; ?>"><?php echo $row ['titre_annonce']; ?></a>
<table style="margin-top:30px;">
<td style=" width:100px;"><?php echo $row ['prix_annonce']; ?><BR><?php echo $row ['ville_annonce']; ?></td>
<td style="padding-left:30px;width:500px;"><?php echo $row ['commentaire']; ?><br><?php echo $row ['type_annonce']; ?> publiée dans annonce: <?php echo $row ['libele_typecat']; ?> le <?php echo $id_date; ?></td>
<td style="padding-left: 20px; padding-bottom:50px;width:100px;"><?php echo $row ['userType']; ?></td>
</table>
</td>
</tr>
<hr>
</table>
<?php } }
else{?> Aucun résultat trouvé...
<!-- FIN AFFICHAGE RECHERCHE-->
<!-- DEBUT AFFICHAGE PAGINATION-->
<?php }?>
<p style="text-align:center;">
<?php
for($i=1;$i<=$pagesTotales;$i++) {
if($i == $pageCourante) {
echo $i.' ';
} else {?>
<?php echo '<a href="TESTMYADS.php?page='.$i.'">'.$i.'</a> ';?>
<?php }
}
?>
</p>
<!-- FIN AFFICHAGE RECHERCHE-->
</div>
</div>
</div>
</div>
</div >
....
</body>
</html>
Bien à vous