/    Sign up×
Community /Pin to ProfileBookmark

pagenation with glob

Hi,

I have used glob to display all the jpg’s from a dir.

Is there a way i can add pagenation to this?

there are something close to 500 photos(Thumbs) which is too much for one page.

[url]http://lendrum.co.nz/wedding/[/url]

[code=php]
<?php

$dir = “./thumbs/”;

$full = “./”;

foreach (glob(“*.jpg”) as $file) {
echo(“<li><a href=”image.php?show=”.$full. $file.””><img src=””.$dir.$file.”” alt=”” /></a></li>”.”n”);
}

?>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bokehOct 09.2006 — Try this. Not tested:[code=php]<?php

$dir = "./thumbs/";

$full = "./";

$content = null;

$page = isset($_GET['page']) ? $_GET['page'] : null ;

$results_per_page = 25;

if(($count = count($files = glob("*.jpg"))) > 0)
{
$total_pages = $count ? ceil($count / $results_per_page) : 1 ;
$page = ((is_numeric($page)) and ($page >= 1) and ($page <= $total_pages)) ? (int)$page : 1 ;
$files = array_slice($files, (($results_per_page * $page) - $results_per_page), $results_per_page);
$content .= '<ul id="gallery">'."n";
foreach($files as $file)
{
$content .= '<li><a href="image.php?show='.$full.$file.'"><img src="'.$dir.$file.'" alt=""></a></li>'."n";
}
$content .= '</ul>'."n";
$content .= pagination_links($page, $count, $results_per_page);
}

function pagination_links($page, $count, $results_per_page, $each_direction = 5)
{
$word_for_previous = 'previous';
$word_for_next = 'next';
$total_pages = $count ? ceil($count / $results_per_page) : 1 ;
$page = ((is_numeric($page)) and ($page >= 1) and ($page <= $total_pages)) ? (int)$page : 1 ;
$output = null;
if($page > 1)
{
$output .= '<a href="'.htmlentities($_SERVER['PHP_SELF']).'?page='.($page - 1).'">'.$word_for_previous.'</a> | '."n";
}
for($i = $page - $each_direction; $i <= $page + $each_direction; $i++)
{
if(($i > 0) and ($i <= $total_pages))
{
$output .= isset($spacer) ? $spacer : null ;
$spacer = ' | '."n";
if($page != $i)
{
$output .= '<a href="'.htmlentities($_SERVER['PHP_SELF']).'?page='.$i.'">'.$i.'</a>'."n";
}
else
{
$output .= $i."n";
}
}
}
if($page < $total_pages)
{
$output .= ' | <a href="'.htmlentities($_SERVER['PHP_SELF']).'?page='.($page + 1).'">'.$word_for_next.'</a>'."n";
}
return '<p class="pagination-links">'."n".$output."n".'</p>';
}

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<style type="text/css">
ul#gallery {
margin:0 auto;
padding:0;
list-style-type:none;
width:90%;
font-family: Tahoma
}

ul#gallery li {
float: left;
margin:10px 15px;
}

ul#gallery li img {
border:0;
}

ul#gallery li p
{
text-align: center;
margin:5px 0;
}
ul#gallery li p a {
text-decoration: none;
color: #000;
}
p.pagination-links{
clear:both;
margin:0;
padding:2em 0 1em 0;
text-align:center;
}
</style>

<title>Sheldon &amp; Shona Lendrum</title>

</head>

<body>
<h1>Sheldon &amp; Shona Lendrum</h1>
<h3>16 September 2006</h3>
<h5>Click to enlarge</h5>
<a href="../orderofservice.pdf">Order of Service</a><br />

<?php echo $content ?>

</body>
</html>[/code]
Copy linkTweet thisAlerts:
@SheldonauthorOct 09.2006 — Fantastic Bokeh!!!

Thanks heaps!
×

Success!

Help @Sheldon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...