Pagination Php. Lien qui n'affiche rien
Bonsoir !! J'appelle à vos connaissances pour m'aider à régler un petit problème.
Actuellement je travaille sur un système de pagination avec SQL et PHP, Mon probleme est qu'a partir d'une recherche qui prend en compte un choix de type checkbox et un autre choix a partir d'une liste affiche les resultats correspondants. Les resultats s'affiche normalement.
Maintenant je veux faire un systeme de pagination avec les resultats mais mon probleme est que les liens n'affichent rien du tout.. Je fais des recherches depuis un mois sans trouver la solution.
Merci de votre Soutien.
Voici le code de mon index.php
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
|
<?php
require_once('Dbconfig.php');
?>
<table align="center" border="1" width="100%" height="100%" id="data">
<?php
$query="";
//traitetement de la requete
if(!empty($_POST['recherche'] ) ){
//Si l'utilisateur a entre quelque chose on traite sa requete
$recherche = preg_replace("#[^a-zA-Z ?0-9]#i", "", $_POST['recherche']);
if($_POST['filtre'] == "nommedicament"){
$query = "SELECT NOM_MEDICAMENT AS Nom, DCI, LABORATOIRE_TITULAIRE_AMM AS Laboratoire, DATE_ATTRIBUTION_AMM AS Date, ETAT_AMM AS Etat FROM medicament WHERE NOM_MEDICAMENT LIKE ?";
}else if($_POST['filtre'] == "dci"){
$query = "SELECT NOM_MEDICAMENT AS Nom, DCI, LABORATOIRE_TITULAIRE_AMM AS Laboratoire, DATE_ATTRIBUTION_AMM AS Date, ETAT_AMM AS Etat FROM medicament WHERE DCI LIKE ?";
}else if($_POST['filtre'] == "numeroamm"){
$query = "SELECT NOM_MEDICAMENT AS Nom, DCI, LABORATOIRE_TITULAIRE_AMM AS Laboratoire, DATE_ATTRIBUTION_AMM AS Date, ETAT_AMM AS Etat FROM medicament WHERE LABORATOIRE_TITULAIRE_AMM LIKE ?";
}}
$records_per_page=4;
$newquery = $paginate->paging($query,$records_per_page);
$paginate->dataview($newquery);
$paginate->paginglink($query,$records_per_page);
?>
</table>
</td>
</tr>
</table>
</body> |
Voici le code la pagination
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| <?php
class paginate
{
private $db;
function __construct($DB_con)
{
$this->db = $DB_con;
}
public function dataview($query)
{
$stmt = $this->db->prepare($query);
if(isset($_POST['choix1'])){
$stmt->execute(array($_POST['recherche'].'%'));
}else if(isset($_POST['choix2'])){
$stmt->execute(array('%'.$_POST['recherche'].'%'));
}
$count = $stmt->rowCount();
if($count >=0)
{
$compteur=0;
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $compteur=$compteur + 1; ?></td>
<td><?php echo $row['Nom']; ?></td>
<td><?php echo $row['DCI'];?></td>
<td><?php echo $row['Laboratoire']; ?> </td>
<td><?php echo $row['Date']; ?></td>
<td><?php echo $row['Etat']; ?></td>
<td><?php echo '.....................' ?></td>
</tr>
<?php
}
}else {
echo "<hr/> 0 résultats trouvés pour <strong>$recherche</strong><hr/> $sql";
}
}
public function paging($query,$records_per_page)
{
$starting_position=0;
if(isset($_GET["page_no"]))
{
$starting_position=($_GET["page_no"]-1)*$records_per_page;
}
$query2 = $query."limit $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query,$records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
if(isset($_POST['choix1'])){
$stmt->execute(array($_POST['recherche'].'%'));
}else if(isset($_POST['choix2'])){
$stmt->execute(array('%'.$_POST['recherche'].'%'));
}
$total_no_of_records = $stmt->rowCount();
if($total_no_of_records > 0)
{
?><tr><td colspan="3"><?php
$total_no_of_pages=ceil($total_no_of_records/$records_per_page);
$current_page=1;
if(isset($_GET["page_no"]))
{
$current_page=$_GET["page_no"];
}
if($current_page!=1)
{
$previous =$current_page-1;
echo "<a href='".$self."?page_no=1'>First</a> ";
echo "<a href='".$self."?page_no=".$previous."'>Previous</a> ";
}
for($i=1;$i<=$total_no_of_pages;$i++)
{
if($i==$current_page)
{
echo "<strong><a href='".$self."?page_no=".$i."' style='color:red;text-decoration:none'>".$i."</a></strong> ";
}
else
{
echo "<a href='".$self."?page_no=".$i."'>".$i."</a> ";
}
}
if($current_page!=$total_no_of_pages)
{
$next=$current_page+1;
echo "<a href='".$self."?page_no=".$next."'>Next</a> ";
echo "<a href='".$self."?page_no=".$total_no_of_pages."'>Last</a> ";
}
?></td></tr><?php
}
}
} |
Voici le fichier Dbconfig.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "bd_amm_sen";
try
{
$DB_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
$DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exception)
{
echo $exception->getMessage();
}
include_once 'Class.paging.php';
$paginate = new paginate($DB_con); |