Bonjour,
j'essaye de faire une pagination a mon table de cours, ça marche masi toujours manque une ligne et si j'ai qu'un seul enregistrement dans table cours s'affiche pas, ceci comment je me débrouille
collecte cours de DB, selon le niveau ( nivo) ou afficher tous le cours,
Affichage
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 <?php if (isset($_GET['nivo']) and !empty($_GET['nivo'])){ $nivo = $_GET['nivo']; $sql = "SELECT * from cours where nivo='$nivo' AND idpro='$id'"; } else{ $sql = "SELECT * FROM cours WHERE idpro='$id' order by id"; } if(isset($_GET['starting'])){ //starting page $starting=$_GET['starting']; }else{ $starting=0; } $recpage = 10; $obj = new pagination_class($sql,$starting,$recpage); $result = $obj->result; ?>
Pagination_class.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 ............ <?php if(mysql_fetch_row($result)!=0){ while($data = mysql_fetch_array($result)) {?> <tbody> <tr> <td class="first style1"><?php echo $data['matiere']; ?> </td> <td><?php echo $data['description']; ?></td> <td> <a href="modifierArt.php?idart=<?php echo $data['id']; ?>" title="Modifier cours "> <img src="images/edit-icon.gif" width="16" height="16" alt="" /> </a></td> <td><a href="cours_html.php?idart=<?php echo $data['id'];?>&action=sup" title=" Supprimer cours " onclick="return confirm('Etes vous sur de vouloir supprimer ce cours ?');"> <img src="images/hr.gif" width="16" height="16" alt="" /></a></td> </tr></tbody> <?php } ?> <tfoot> <tr id="nav"><td colspan="5"><div><?php echo $obj->anchors; ?></div></td></tr> <tr id="total"><td colspan="5"><?php echo $obj->total; ?></td></tr> <?php } else{ ?> <tr><td align="center" colspan="5">Rien trouvé/td> </tr></tfoot> <?php } ?>
Merci d'avance,
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 <?php class Pagination_class{ var $result; var $anchors; var $total; function Pagination_class($qry,$starting,$recpage) { include('_db.php'); $rst = mysql_query($qry) or die(mysql_error()); $numrows = mysql_num_rows($rst); $qry .= " limit $starting, $recpage"; $this->result = mysql_query($qry) or die(mysql_error()); $next = $starting+$recpage; $var = ((intval($numrows/$recpage))-1)*$recpage; $page_showing = intval($starting/$recpage)+1; $total_page = ceil($numrows/$recpage); if($numrows % $recpage != 0){ $last = ((intval($numrows/$recpage)))*$recpage; }else{ $last = ((intval($numrows/$recpage))-1)*$recpage; } $previous = $starting-$recpage; $anc = "<ul id='pagination-flickr'>"; if($previous < 0){ $anc .= "<li class='previous-off'>Premier</li>"; $anc .= "<li class='previous-off'>Préc</li>"; }else{ $anc .= "<li class='next'><a href='articles_.php?starting=0'>Premier </a></li>"; $anc .= "<li class='next'><a href='articles_.php?starting=$previous'>Préc </a></li>"; } ################If you dont want the numbers just comment this block############### $norepeat = 4;//no of pages showing in the left and right side of the current page in the anchors $j = 1; $anch = ""; for($i=$page_showing; $i>1; $i--){ $fpreviousPage = $i-1; $page = ceil($fpreviousPage*$recpage)-$recpage; $anch = "<li><a href='articles_.php?starting=$page'>$fpreviousPage </a></li>".$anch; if($j == $norepeat) break; $j++; } $anc .= $anch; $anc .= "<li class='active'>".$page_showing."</li>"; $j = 1; for($i=$page_showing; $i<$total_page; $i++){ $fnextPage = $i+1; $page = ceil($fnextPage*$recpage)-$recpage; $anc .= "<li><a href='articles_.php?starting=$page'>$fnextPage</a></li>"; if($j==$norepeat) break; $j++; } ############################################################ if($next >= $numrows){ $anc .= "<li class='previous-off'>Suiv</li>"; $anc .= "<li class='previous-off'>Dernier</li>"; }else{ $anc .= "<li class='next'><a href='articles_.php?starting=$next'>Suiv </a></li>"; $anc .= "<li class='next'><a href='articles_.php?starting=$last'>Dernier</a></li>"; } $anc .= "</ul>"; $this->anchors = $anc; $this->total = "Page : $page_showing <i> de </i> $total_page . Résultat Total: $numrows"; } } ?>
Partager