Système de pagination avec bdd et images (fichiers)

Contenu du snippet

Azul à tous,

Dans ce petit programme, j'ai implémenté un système de pagination sur des données que je lis à partir d'une table et dont des fichiers correspondants se trouvent dans un dossier (des images, dans mon cas)

Je poste ce script surtout pour avoir des suggestion à l'améliorer.
Il fonctionne parfaitement

Source / Exemple :


<?php
require_once('include/header.inc.php');
require_once('include/leftMenu.inc.php');
require_once('Cfg/config.inc.php');
?>
<div class="rightContent">
<?php
 $tal=$_GET['ta2'];
 $tenq=$_GET['tenq'];
 /*it is the page concerned by this show*/
 $pagen="lister.php";
 $start=$_GET['start'];
 if(strlen($start)>0&&!is_numeric($start)){
 	echo'Erreur dans le paramètre passée';;
 	exit();/*i go out from this page*/
 }
$eu = ($start - 0); 
$limit = 2;                                 
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 
//i will fetch for the number of records in my table
$query2="SELECT*FROM $tenq";
// so as to help me to break the page
$result2=mysql_query($query2)or die('Impossible to perform the SELECTION query 1<br/>'.mysql_error());
$nume=mysql_num_rows($result2);
/* Thus we have just stored the number of rows that exist in our table */
/* now i will print the table headers in which i will save the elemens of my table*/
$bgcolor="#f1f1f1";
echo "<TABLE width=50% align=center  cellpadding=0 cellspacing=0 class=mytableinlister>";
$query=" SELECT * FROM $tenq  limit $eu, $limit ";
$result=mysql_query($query)or die('Impossible to perform the SELECTION query 2<br/>'.mysql_error());
/* now i will display my stupid data within this table i just started drawing */
while($broughtdata = mysql_fetch_array($result))
{
if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}
echo "<tr >";
echo "<td align=center bgcolor=$bgcolor id='title'>&nbsp;<font face='Verdana' size='2'>$broughtdata[ufn]</font></td>";
echo'</tr>';
echo'<tr>';
echo'<td align="center">';
$sfn=$broughtdata['sfn'];
$wherearemyimages="admin/Images";
$openmywami=opendir($wherearemyimages);
while($myfilelookedfor=readdir($openmywami)){
	$thelinktomf=$wherearemyimages.'/'.$myfilelookedfor;
	if(file_exists($thelinktomf)&&$broughtdata['sfn']==$myfilelookedfor){
		echo"<a href=\"productsdetails.php?idImg=$idphoto#portsdetailslabel\"><img src=\"".$thelinktomf."\" width=\"150\" height=\"150\" border=\"0\"/></a></td>";
	}
}	
echo'</td>';
echo'</tr>';
}
echo "</table>";
/*i have just ended displaying my data in this table */
if($nume > $limit ){ 
/*i will display links under this table if sufficient records are there to page */
/* thus the links to show are the previous and next links with page numbers*/
echo "<table align = 'center' width='50%'><tr><td  align='left' width='30%'>";
/*if the variable $back is equal to 0 or more then only we will display the link Previous so as

  • to move back within my table */
if($back >=0) { print "<a href='$page_name?start=$back&tenq=$tenq'><img src=\"images/previous.jpeg\" border=\"0\"></a>"; } /* here again, i display my links at the center,
  • but i must avoid displaying the current page as a link*/
echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i&tenq=$tenq'><font face='Verdana' size='2'>$l</font></a> "; } else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; /*if this is nopt the last page then we can display the following link
  • I verify this here */
if($this1 < $nume) { print "<a href='$page_name?start=$next&tenq=$tenq'><img src=\"images/next.jpeg\" border=\"0\"></a>";} echo "</td></tr></table>"; }// end of if verifying sufficient records are there to display bottom navigational link. ?> </div> <?php require_once('include/footer.inc.php'); ?>

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.