1

我有一个 php 页面来显示来自 mysql 数据库的图像。它一个接一个地显示在 1 页中上传的所有图像。如何通过分页显示每页 5 或 6 张图像?

这是我的php页面。

<?Php

    include("init.php"); 
    include("template/header.php");


    ?>
    <div class="view_albums"><h3> View Albums </h3>;
    <?php



    $album_id = $_GET['album_id'];
    $images = get_images($album_id);

    if (empty($images)) {
        echo 'There are no images ';

    } else {


        foreach ($images as $image) {
            ?> <div class="box">  <?php
            echo '<a href="uploads/', $image['album'], '/', $image['id'], '.', $image['ext'],'"> <img class="box1" src="uploads/thumbs/', $image['album'], '/', $image['id'], '.', $image['ext'], '"  title="Uploaded on ', date('l F j, Y \a\t g:i A',$image['timestamp']),'"></a> [<a href="delete_image.php?image_id=">delete</a>]';
            ?>  <?php


        }
    }
    ?>
    </div>
    </div>
    <?php
    include("template/footer.php");

?>
4

1 回答 1

0

尝试使用下面的分页功能

function genPagination($total,$currentPage,$baseLink,$nextPrev=true,$limit=10) 
{ 
if(!$total OR !$currentPage OR !$baseLink) 
{ 
    return false; 
} 

//Total Number of pages 
$totalPages = ceil($total/$limit); 

//Text to use after number of pages 
$txtPagesAfter = ($totalPages==1)? " page": " pages"; 

//Start off the list. 
$txtPageList = '<br />'.$totalPages.$txtPagesAfter.' : <br />'; 

//Show only 3 pages before current page(so that we don't have too many pages) 
$min = ($page - 3 < $totalPages && $currentPage-3 > 0) ? $currentPage-3 : 1; 

//Show only 3 pages after current page(so that we don't have too many pages) 
$max = ($page + 3 > $totalPages) ? $totalPages : $currentPage+3; 

//Variable for the actual page links 
$pageLinks = ""; 

//Loop to generate the page links 
for($i=$min;$i<=$max;$i++) 
{ 
    if($currentPage==$i) 
    { 
        //Current Page 
        $pageLinks .= '<b class="selected">'.$i.'</b>'; 
    } 
    else 
    { 
        $pageLinks .= '<a href="'.$baseLink.$i.'" class="page">'.$i.'</a>'; 
    } 
} 

if($nextPrev) 
{ 
    //Next and previous links 
    $next = ($currentPage + 1 > $totalPages) ? false : '<a href="'.$baseLink.($currentPage + 1).'">Next</a>'; 

    $prev = ($currentPage - 1 <= 0 ) ? false : '<a href="'.$baseLink.($currentPage - 1).'">Previous</a>'; 
} 

return $txtPageList.$prev.$pageLinks.$next; 

}  

认为它会帮助你

于 2013-03-07T10:06:30.103 回答