Bonjour. J'essaie depuis quelque temps à créer une pagination en me basant sur PDO et Jquery. Et j'ai un bogue que je n'arrive pas à résoudre.

Quelque chose ne va pas dans l'un de mes fichiers.

Ma ligne 84 de index.php $pagination indéfinit même s'il est.

mon index.php:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php session_start();
include("bdd.inc.php");
 
$item_par_page = 2;
$categorie = "peinture";
 
$lenombre = $dbh->prepare("
                      SELECT
                        categorie.categorie,
                        users.id,
                        users.firstname,
                        users.lastname,
                        COUNT(*) AS nb
                      FROM
                        categorie
                      INNER JOIN images ON categorie.id = images.categorieid
                      INNER JOIN users ON images.usersid = users.id
                      WHERE
                        categorie = :categorie
                      ORDER BY
                        categorie.id DESC,
                        users.id DESC
                     ");
 
$lenombre->bindParam(':categorie', $categorie, PDO::PARAM_STR, 44);
$lenombre->execute();
 
while ($compte = $lenombre->fetchObject())
{ $_SESSION['compte'] = $compte->nb; } 
$get_total_rows = $_SESSION['compte'];
 
//break total records into pages
$pages = ceil($get_total_rows/$item_par_page);    
 
//create pagination
if($pages > 1)
{
    $pagination     = '';
    $pagination .= '<ul class="paginate">';
    for($i = 1; $i<$pages; $i++)
    {
        $pagination .= '<li><a href="#" class="paginate_click" id="'.$i.'-page">'.$i.'</a></li>';
    }
    $pagination .= '</ul>';
}
 
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="jquery-1.9.0.min.js"></script>
 
<script type="text/javascript">
        $(document).ready(function() {
            $("#results").load("pratique_1.php", {'page':0}, function() {$("#1-page").addClass('active');});  //initial page number to load
 
            $(".paginate_click").click(function (e) {
 
                $("#results").prepend('<div class="loading-indication"><img src="ajax-loader.gif" /> Loading...</div>');
 
                var clicked_id = $(this).attr("id").split("-"); //ID of clicked element, split() to get page number.
                var page_num = parseInt(clicked_id[0]); //clicked_id[0] holds the page number we need 
 
                $('.paginate_click').removeClass('active'); //remove any active class
                $("#results").load("pratique_1.php", {'page':(page_num-1)}, function(){
 
                });
 
                $(this).addClass('active'); //add active class to currently clicked element (style purpose)
 
                return false; //prevent going to herf link
            });    
        });
</script>
 
<link href="style.css" rel="stylesheet" type="text/css">
 
</head>
<body>
 
<div id="results"></div>
<?php echo $pagination; ?>
 
</body>
</html>
Fichier pratique_1.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php session_start();
 
$item_par_page = 2;
$categorie = "peinture";
 
require ('bdd.inc.php');
 
//sanitize post value
$page_number = $_POST['page'];
 
//get current starting point of records
$position = ($page_number * $item_par_page);
 
$artiste = $dbh->prepare("
                      SELECT
                        categorie.categorie,
                        users.id,
                        users.firstname,
                        users.lastname
                      FROM
                        categorie
                      INNER JOIN images ON categorie.id = images.categorieid
                      INNER JOIN users ON images.usersid = users.id
                      WHERE
                        categorie = :categorie
                      ORDER BY
                        categorie.id DESC,
                        users.id DESC
                      LIMIT :position, :item_par_page
                     ");
 
$artiste->bindParam(':categorie', $categorie, PDO::PARAM_STR, 44);
$artiste->bindParam(':position', $position, PDO::PARAM_INT, 3);
$artiste->bindParam(':item_par_page', $item_per_page, PDO::PARAM_INT, 3);
$artiste->execute();
 
echo '<ul class="page_result">';
while ($row = $artiste->fetchObject())
{ 
  echo '<li id="item_'.$row->id.'">'.$row->id.'. <span class="page_name">'.$row->firstname.'</span><span class="page_message">'.$row->lastname.'</span></li>';
}
echo '</ul>';
 
?>
Bon.. si je peux avoir de l'aide.. ça serait bien. Merci.