Bonjour,
Ce script qui m'a été fourni pour un affichage page par page des informations issues d'une bdd ne fonctionne pas sur un point :
la variable "$limit" qui est censée s'incrémenter s'il y a plusieurs pages à afficher demeure figée à "0". Ainsi, ma 1ère page s'affiche avec le lien "Page suivante", mais lorsque je clique dessus rien ne se passe.
Voici mon code:
Merci sincèrement pour votre aide !
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 // connecting to database //======================= $server = "localhost"; $user = "root"; $pwd = ""; $connect = mysql_connect($server, $user, $pwd) or die ("Erreur : ".mysql_error()); $db = "gallery"; $table = "objects"; $select_db = mysql_select_db($db, $connect) or die ("Erreur : ".mysql_error()); // initializing variables //======================= $msg = ""; $results_pg = 4; // number of results to display per page if(!isset($limit)) $limit=0; // $limit = start point // getting page's name //==================== $path_parts = pathinfo($_SERVER['PHP_SELF']); $pgName = $path_parts['basename']; // counting total records in table //================================ $count = "SELECT COUNT(id) FROM objects"; $result = mysql_query($count, $connect); $row = mysql_fetch_row($result); $totalRows = $row[0]; // running 'Tables' query //======================= $select = 'SELECT * FROM objects ORDER BY name ASC LIMIT '.$limit.','.$results_pg; $result = mysql_query($select, $connect) or die ("Erreur : ".mysql_error()); // recalculating $limit to know if other results to display //========================================================= $nextLimit = $limit + $results_pg; $prevLimit = $limit - $results_pg; // display link to previous page if necessary //=========================================== if($limit != 0) { echo '<a href="'.$pgName.'?limit='.$prevLimit.'">Page précédente</a>'; } // display link to next page if necessary //======================================= if($nextLimit < $totalRows) { echo '<a href="'.$pgName.'?limit='.$nextLimit.'">Page suivante</a>'; } echo '<br>'.$limit.'<br>'.$nextLimit; ?>
Partager