Pagination

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Pagination

par Cyrano » 27 sept. 2005, 18:29

Pour information, je viens de mettre un script pour expliquer le système dans la FAQ

par heddicmi » 27 sept. 2005, 15:25

tout d'abord, lorsque tu mets du code PHP, utilise la balise PHP plut^to que Code ;)

Ensuite, je te conseil de faire un tour sur ce tutorial assez explicite...

pagination

par Invité » 27 sept. 2005, 15:16

heddicmi,
Merci pour ton conseil.
J'ai pense avoir compris comment ca functionne, mais je n'arrive pas à integrer tout ca dans le script...
:(

par heddicmi » 27 sept. 2005, 14:55

Pour jouer avec les paginations, il te faut utiliser 2 choses :
- La notion de LIMIT pour ta requête de récupération d'image (histoire de ne pas te surcharger de réponses inutiles...
- Une variable repère $debut par exemple...

Cette dernière est égale à 0 au début, d'où :
Limit $debut, 15 => les 15ères photos...

Du ocup, dans ta page, tu jours ensuites avec pour les boutons de pages suivantes et précédentes... viewgallery.php?debut=$debut+15... Comme ça, si tu cliques sur suivant, debut aura la valeur 15 et te récupèreras les photos de :
Limit 15, 15 => 15 photos suivantes, puis :
Limit 30, 15, etc...

Renseigne toi donc dans la doc mysql sur limit...

Pagination

par Invité » 27 sept. 2005, 14:47

Bonjour

J'ai trouvé un script pour creer une galerie des photos. J'ai ma page viewgallery.php qui affiche les categories d'images. Dans les categories j'affiche les miniatures avec les liens pour voir les images en taille reel.
Il y a une chose que j'aimerai faire.
En fait, j'aimerai afficher que 15 miniatures par page (dans les categories) et en bas de la page afficher "suivante" t "précedente" pour navigation entre les pages.
J'ai trouvé les explications sur internet et j'ai reussi afficher nombre limité d'image sur ma page. Par contre, pour la navigation, c'est pas gagné...
help!!!

Merci d'avance


Viewgallery.php :

Code : Tout sélectionner

<?php include '../Connections/config.ini.php'; // initialization $result_array = array(); $counter = 0; $cid = isset($_GET['cid']) ? (int)($_GET['cid']) : 0; $pid = isset($_GET['pid']) ? (int)($_GET['pid']) : 0; $number_of_photos_in_row = ''; $result_final =''; // Category Listing if( empty($cid) && empty($pid) ) { $number_of_categories_in_row = 1; $result = mysql_query( "SELECT c.category_id,c.category_name,COUNT(photo_id) FROM gallery_category as c LEFT JOIN gallery_photos as p ON p.photo_category = c.category_id GROUP BY c.category_id" ); while( $row = mysql_fetch_array( $result ) ) { $result_array[] = "<a href='viewgallery.php?cid=".$row[0]."'>".$row[1]."</a> "."(".$row[2].")"; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $category_link) { if($counter == $number_of_categories_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= "\t<td>".$category_link."</td>\n"; } if($counter) { if($number_of_categories_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\n"; $result_final .= "</tr>"; } } // Thumbnail Listing else if( $cid && empty( $pid ) ) { $number_of_thumbs_in_row = 5; $result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos WHERE photo_category='".addslashes($cid)."'" ); $nr = mysql_num_rows( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Category found</td></tr>\n"; } else { while( $row = mysql_fetch_array( $result ) ) { $result_array[] = "<a target='_blank' href='$images_dir/".$row[2]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /><br />".$row[1]."</a>";; } mysql_free_result( $result ); $result_final = "<tr>\n"; foreach($result_array as $thumbnail_link) { if($counter == $number_of_thumbs_in_row) { $counter = 1; $result_final .= "\n</tr>\n<tr>\n"; } else $counter++; $result_final .= "\t<td>".$thumbnail_link."</td>\n"; } if($counter) { if($number_of_photos_in_row-$counter) $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</td>\n"; $result_final .= "</tr>"; } } } // Full Size View of Photo else if( $pid ) { $result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" ); list($photo_caption, $photo_filename) = mysql_fetch_array( $result ); $nr = mysql_num_rows( $result ); mysql_free_result( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Photo found</td></tr>\n"; } else { $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" ); list($category_name) = mysql_fetch_array( $result ); mysql_free_result( $result ); $result_final .= "<tr>\n\t<td> <a href='viewgallery.php'>Catégorie</a> > <a href='viewgallery.php?cid=$cid'>$category_name</a></td>\n</tr>\n"; $result_final .= "<tr>\n\t<td align='center'> <br /> <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' /> <br /> $photo_caption </td> </tr>"; } } // Final Output echo <<<__HTML_END <html> <head> <title>Mariage Julia et Bruno le 13 Août 2005</title> </head> <body> <style type="text/css"> a:link { text-decoration: none; color: #FF6600; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; } a:visited { text-decoration: none; color: #FF6600; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; } a:hover { text-decoration: none; color: #FF6600; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; } a:active { text-decoration: none; color: #FF6600; font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; } .Style2 { font-size: 12px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; color: #FF0000; } .Style3 { font-size: 14px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; color: #FF0000; } .Style4 { font-size: 14px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; color: #FF6600; } </style> <table width="750" height="100%" border="0" align="center" cellpadding="0" cellspacing="0" background="fond.jpg"> <tr> <td height="181" colspan="2" valign="top"><img src="bondo.jpg" width="749" height="181"></td> <td width="750" height="50"></td> </tr> <td valign="top"><table width='650' border='0' align='center'> <br></br> $result_final <td align="left"> <br></br> <font class="Style2">Pour ajouter vos photos dans notre galerie <a href="preupload.php" class="Style4">cliquez ici</a></font> </td> </table></td> </table> </body> </html> __HTML_END; ?>