Bonjours
J'ai crée une page affichant un listing sous forme de tableau. Je n'arrive pas à faire une fonction qui permetra de limiter le nombre de lignes dans une page.
De plus je souhaiterai trouver une fonction qui me permetra d'afficher la suite du listing dans une autre page en utilisant le bouton suivant ou précédent.
test.php
fonction_test.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 <?php session_start(); require('fonction_test.php'); mysql_connect("localhost","root",""); mysql_select_db("test"); $sql = "SELECT ref,nom,prenom,age FROM inscris"; $exec = mysql_query($sql); $af = array(); $i=0; while ($res = mysql_fetch_object($exec)){ $af[$i][0]=$res->ref; $af[$i][1]=$res->nom; $af[$i][2]=$res->prenom; $af[$i][3]=$res->age; $i++; } $_SESSION["af"]=$af; ?> <html> <head> </head> <body> <form method="post" action="traitement.php"/> <table border="1" align="center"> <tr> <td colspan="4" align="center"><b>test de tableau</b></td> </tr> <tr> <td colspan="1"><b>Référence</b></td> <td colspan="1"><b>Nom de l'entreprise</b></td> <td colspan="1"><b>Nom</b></td> <td colspan="1"><b>Prénom</b></td> </tr> <?php afficher_test($af); ?> </table> </form> </body> </html>
traitement.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 <?php function afficher_test($af){ $taille = sizeof($af); if ($taille-1 <= 4){$limite = $taille-1;} else {$limite = 4;} //----------------------------------- for ($i = 0; $i <= $limite+4; $i++){ if ($af[$i][0] != 0){ echo "<tr><td colspan='1'>"; echo $af[$i][0]; echo "</td><td colspan='1'>"; echo $af[$i][1]; echo "</td><td colspan='1'>"; echo $af[$i][2]; echo "</td><td colspan='1'>"; echo $af[$i][3]; echo "</td></tr>"; }} echo "<tr><td colspan='1'>"; echo "<input type='submit' value='Précédent' name='action'/>"; echo "</td><td colspan='2'>"; echo "Nombre de page"; echo "</td><td colspan='1'>"; echo "<input type='submit' value='Suivant' name='action'/>"; echo "</td></tr>"; } ?>
Pouvez vous me donner un lien où trouver ce code qui permet d'afficher la suite du listing dans une autre page en utilisant les boutons, ou me completer le script de traitement afin de faire cela?
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 <?php session_start(); mysql_connect("localhost","root",""); mysql_select_db("test"); require('fonction_test.php'); $action = $_POST['action']; if ($action=="Suivant"){ //ici on met la page+ref permetant d'afficher la suite du listing dans une autre page. } elseif ($action=="Précédent"){ //ici on met la page+ref permetant de revenir au listing dans de l'ancienne page. } } else{header("location:test.php");} ?>
J'ai fais une recherche sur google avec : php + listing + suivant + precedent . j ai rien trouver.
Partager