Moteur de recherche avec filtre checkboxe et pagination des résultats
Bonjour,
Je fais quelque code mais je suis encore loin d’être pro.
J'ai crée une page de recherche dans ma BD et je souhaiterai associé le moteur de recherche avec checkbox, et faire le pagination des resulats.
Actuellement, le moteur de recherche, ça marche mais les filtres checkboxe ne fonctionne pas et la pagination je ne connais pas comment faire le précédent, suivant, début, fin pour ne avoir toute les numéros de pages.
Merci vos aides.
Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| <?php
define("ROW_PER_PAGE",5);
require_once('db.php');
?>
<html>
<head>
<link type="text/css" href="css/style_table.css" rel="stylesheet" />
<style>
.button_link {color:#FFF;text-decoration:none; background-color:#428a8e;padding:10px;}
#keyword{border: #CCC 1px solid; border-radius: 4px; color:#28AB4F; padding: 10px;background:url("demo-search-icon.png") no-repeat center right 7px;}
.btn-page{margin-right:2px;padding:5px 10px; border: #CCC 1px solid; background:#FFF; border-radius:4px;cursor:pointer; border-color:#28AB4F}
.btn-page:hover{background:#3CFF76;}
.btn-page.current{background:#28AB4F; color:#FFF}
</style>
</head>
<body>
<?php
if (isset($_GET['nb_ligne'])) $nb_ligne = $_GET['nb_ligne']; else $nb_ligne='nb_ligne';
if (isset($_GET['genrex'])) $genrex = $_GET['genrex']; else $genrex='genrex';
$search_keyword = '';
if(!empty($_POST['search']['keyword'])) {
$search_keyword = $_POST['search']['keyword'];
}
$sql = 'SELECT * FROM liste WHERE genre="'.$genrex.'" and nom LIKE :keyword OR prenom LIKE :keyword OR num_cin LIKE :keyword OR mat LIKE :keyword
OR lot LIKE :keyword OR quartier LIKE :keyword OR commune LIKE :keyword OR tel1 LIKE :keyword OR genre LIKE :keyword
ORDER BY mat ASC ';
/* Pagination Code starts */
$per_page_html = '';
$page = 1;
$start=0;
if(!empty($_POST["page"])) {
$page = $_POST["page"];
$start=($page-1) * ROW_PER_PAGE;
}
$limit=" limit " . $start . "," . ROW_PER_PAGE;
$pagination_statement = $pdo_conn->prepare($sql);
$pagination_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pagination_statement->execute();
$row_count = $pagination_statement->rowCount();
if(!empty($row_count)){
$per_page_html .= "<div style='text-align:center;margin:5px 0px;'>";
$page_count=ceil($row_count/ROW_PER_PAGE);
if($page_count>1) {
for($i=1;$i<=$page_count;$i++){
if($i==$page){
$per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page current" />';
} else {
$per_page_html .= '<input type="submit" name="page" value="' . $i . '" class="btn-page" />';
}
}
}
$per_page_html .= "</div>";
}
$query = $sql.$limit;
$pdo_statement = $pdo_conn->prepare($query);
$pdo_statement->bindValue(':keyword', '%' . $search_keyword . '%', PDO::PARAM_STR);
$pdo_statement->execute();
$result = $pdo_statement->fetchAll();
?> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<table cellspacing='0' cellpadding='0' border='1' align='center' width='900'>
<tr>
<td align="left" valign="top">
<table border-radius="4" cellpadding="0" cellspacing="0">
<tr>
<td align="center" bgcolor="bleu"> <br><b>Homme</b><br><input type="radio" style='border-radius:0px;width:100px;height:20px;' name="genrex" value="HOMME"><br> </td>
<td align="center" bgcolor="bleu"> <br><b>Femme</b><br><input type="radio" style='border-radius:0px;width:100px;height:20px;' name="genrex" value="FEMME"><br> </td>
<td align="center" bgcolor="bleu"> <br><b>Tous</b><br><input type="radio" style='border-radius:0px;width:100px;height:20px;' name="genrex" checked="checked" value=""><br> </td>
<td valign="top" align="center" bgcolor="bleue" width="200"> <br><b> Nbre Ligne</b> <input type="number" style='border-radius:1px;width:40px;height:30px;' name="nb_ligne" value="10" min= "5" step="5" required>
</tr>
</table>
</td>
<td>
<form name='frmSearch' action='' method='post'>
<div style='text-align:right;margin:0px 0px;'><input type='text'
style='border-radius:0px;width:200px;height:40px;font-size:12pt;font-family:Verdana,Arial sans-serif;color:#28AB4F;font-weight:bold;'
name='search[keyword]' placeholder ='Recherche' value="<?php echo $search_keyword; ?>" id='keyword' maxlength='25'></div>
<BR>
</td>
</tr>
</table>
<table class='hoverTable' cellspacing='0' cellpadding='2' border='1' align='center' bordercolor='green' width='900' >
<tr align='center'>
<th width='80'>Matricule</th>
<th width='80'>Genre</th>
<th width='200'>Nom</th>
<th width='250'>Prenom</th>
<th width='150'>CIN</th>
<th width='100'>Contact</th>
</tr>
<?php
if(!empty($result)) {
foreach($result as $row) {
echo "<tr>";
echo "<td align='center'>".$row['mat']."</td>";
echo "<td>".$row['genre']."</td>";
echo "<td>".$row['nom']."</td>";
echo "<td>".$row['prenom']."</td>";
echo "<td align='center'>".$row['num_cin']."</td>";
echo "<td align='center'>".$row['tel1']."</td>";
echo "</tr>";
}
}
?>
</table>
<?php echo $per_page_html;
?>
</form>
</body>
</html> |