这是我用于相同目的的代码。
/****************************************************
To fetch total number of images for pagination
*****************************************************/
$folder_name=$row[page_addlink] ;
$dirname = "gallery/".$folder_name ;
$files = glob($dirname."/*.{jpg,gif,png,tiff,jpeg,bmp}", GLOB_BRACE);
$no_of_files=count($files);
/****************************************************
This is to get total number of records for pagination
*****************************************************/
$rows = $no_of_files;
$pagenum=$_GET[pagenum];
/*******************************************
By default page number is 1
*******************************************/
if (!(isset($pagenum)))
{
$pagenum = 1;
}
/****************************************************
No of rows to be visibles.Value is set in config file
*****************************************************/
$page_rows = $no_of_images_pagination ; /// defined in connection.php file
$last = ceil($rows/$page_rows);
if ($pagenum <= 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
?>
<div class="right_panel">
<div class="inner">
<div class="inner_bg">
</br>
<div align='center'>
<?php
if($rows <=$page_rows)
{
}
else
{
if($pagenum!=1)
{
echo "<a href='[URL of your page]?id=$folder_id&pagenum=1' style='text-decoration:none'> <<-First</a> ";
}
$previous = $pagenum-1;
if($pagenum!=1)
{
echo " <a href='[URL of your page]?id=$folder_id&pagenum=$previous' style='text-decoration:none'><-Previous</a> ";
}
//just a spacer
for($k=1;$k<=$last;$k++)
{
echo " <a href='[URL of your page]?id=$folder_id&pagenum=$k' style='text-decoration:none'>";
if($k==$pagenum)
{
echo "<b><u>".$k."</u></b>" ;
}
else
{
echo $k ;
}
echo "</a> ";
}
$next = $pagenum+1;
if($pagenum!=$last)
{
echo "<a href='[URL of your page]?id=$folder_id&pagenum=$next' style='text-decoration:none'>Next -></a> ";
}
echo " ";
if($pagenum!=$last)
{
echo " <a href='[URL of your page]?id=$folder_id&pagenum=$last' style='text-decoration:none'>Last ->></a> ";
}
}
?>
</div>
您可以根据您的 CSS 和页面 url 和目录位置稍作修改后使用此代码。它工作得非常好。祝你好运