/    Sign up×
Community /Pin to ProfileBookmark

Pagination problem with listing directory result

Good day to you all,
can somebody help me with my pagination, the following code does not give me any error but the pagination part of the script don’t do his job.

[code=php]
<?php

// Images directory lister start script
$image_counter = -1;
$row_counter = 0;
$cell_counter = 0;
$show=array(‘.jpg’,’.JPG’,’.gif’,’.GIF’);
$path = ‘Images/2/’;

$dir_handle = @opendir($path) or die(“Unable to open $path”);

$image_table = “<table valign=”top” align=”center”>n<tr><th colspan=3>Existing Pics in Directory:</th></tr>n<tr>”;
while (false !== ($file = readdir($dir_handle))) {
if(in_array(substr($file,-4,4),$show)){
if(!(($image_counter + 1) % 3)){
$row_counter++;
}
$newpath0 = basename($file,”.*”);
$image_table .=(($image_counter + 1) % 3)? “” : “</tr>n<tr><td><br></td></tr><tr valign=”top”>”;
$image_table .= “n<td valign=”top”><table width=”200″ border=”1″ cellpadding=”0″ cellspacing=”1″ align=”center”>n”;
$image_table .= “n<tr><td align=”center”><b>$newpath0</b></td></tr>n”;
$image_table .= “n<td><img src=”$path$file” width=”200″></td></tr>n”;
$image_table .= “n<tr><td></td></tr>n”;
$image_table .= “n<tr><td><b>Prix :</b> Test</td></tr>n”;
$image_table .= “n<tr><td><b>Prix :</b> Test</td></tr>n”;
$image_table .= “n<tr><td><b>Prix :</b> Test</td></tr>n”;
$image_table .= “n</table></td>nnn”;

++$image_counter;
++$cell_counter;
}

}

$colspan= ($row_counter * 3) – $cell_counter;
$image_table .= ($cell_counter % 3) ? “<td colspan=$colspan>&nbsp;</td>” : “”;
$image_table .= “</tr>n</table>n”;
echo “$image_table<br><br>”;

// Pagination script start
class display {
function pagination($rows, $per_page, $current_page, $page_link) {
global $core,$C;

// Create a Page Listing
$this->pages = ceil($rows / $per_page);

// If there’s only one page, return now and don’t bother
if($this->pages == 1) {
return;
}

// Pagination Prefix
$output .= “<!– Pagination by Dennis Pedrie. Used by Permission –>”;
$output = “Pages: “;

// Should we show the FIRST PAGE link?
if($current_page > 2) {
$output .= “<a href=””. $page_link .”?page=1/” title=”First Page”><<</a>”;
}

// Should we show the PREVIOUS PAGE link?
if($current_page > 1) {
$previous_page = $current_page – 1;
$output .= ” <a href=””. $page_link .”>page=”. $previous_page .”/” title=”Previous Page”><</a>”;
}

// Current Page Number
$output .= “<strong>[ “. $current_page .” ]</strong>”;

// Should we show the NEXT PAGE link?
if($current_page < $this->pages) {
$next_page = $current_page + 1;
$output .= “<a href=””. $page_link .”?page=”. $next_page .”/” title=”Next Page”>></a>”;
}

// Should we show the LAST PAGE link?
if($current_page < $this->pages – 1) {
$output .= ” <a href=””. $page_link .”?page=”. $this->pages .”/” title=”Last Page”>>></a>”;
}

// Return the output.
return $output;
}
}

$display = new display;
echo $display->pagination($row_counter, “2”, “1”, “http://theponther.peuplies.info/AAA%20TEST/Images/images3.php”);

echo “<br>”;
echo “<b>Total Cells w pics: $cell_counter<br>”;
echo “<b>Total Rows: $row_counter<br>”;
echo “<b>Empty Cells in last row: $colspan”;
?>

[/code]

Thanks !

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@PeuplarchieauthorAug 06.2007 — There is 2 script put together in my script :

The first a script that take all image in a directory and display them in a html table in rows of 3.

[code=php]
<?php




$image_counter = -1;
$row_counter = 0;
$cell_counter = 0;
$show=array('.jpg','.JPG','.gif','.GIF');
$path = 'Images/2/';


$dir_handle = @opendir($path) or die("Unable to open $path");

$image_table = "<table valign="top" align="center">n<tr><th colspan=3>Existing Pics in Directory:</th></tr>n<tr>";
while (false !== ($file = readdir($dir_handle))) {
if(in_array(substr($file,-4,4),$show)){
if(!(($image_counter + 1) % 3)){
$row_counter++;
}
$newpath0 = basename($file,".*");
$image_table .=(($image_counter + 1) % 3)? "" : "</tr>n<tr><td><br></td></tr><tr valign="top">";
$image_table .= "n<td valign="top"><table width="200" border="1" cellpadding="0" cellspacing="1" align="center">n";
$image_table .= "n<tr><td align="center"><b>$newpath0</b></td></tr>n";
$image_table .= "n<td><img src="$path$file" width="200"></td></tr>n";
$image_table .= "n<tr><td></td></tr>n";
$image_table .= "n<tr><td><b>Prix :</b> Test</td></tr>n";
$image_table .= "n<tr><td><b>Prix :</b> Test</td></tr>n";
$image_table .= "n<tr><td><b>Prix :</b> Test</td></tr>n";
$image_table .= "n</table></td>nnn";

++$image_counter;
++$cell_counter;
}

}





$colspan= ($row_counter * 3) - $cell_counter;
$image_table .= ($cell_counter % 3) ? "<td colspan=$colspan>&nbsp;</td>" : "";
$image_table .= "</tr>n</table>n";
echo "$image_table<br><br>";


echo "<br>";
echo "<b>Total Cells w pics: $cell_counter<br>";
echo "<b>Total Rows: $row_counter<br>";
echo "<b>Empty Cells in last row: $colspan";
?>


[/code]



The other part, that I want to include would be to "paginate" the result of the first script.

Here in my code I want after 2 rows of 3 image, it would do some next -1-2-3 link to go to the next 2 rows of images.

[code=php]

class display {
function pagination($rows, $per_page, $current_page, $page_link) {
global $core,$C;

// Create a Page Listing
$this->pages = ceil($rows / $per_page);

// If there's only one page, return now and don't bother
if($this->pages == 1) {
return;
}

// Pagination Prefix
$output .= "<!-- Pagination by Dennis Pedrie. Used by Permission -->";
$output = "Pages: ";

// Should we show the FIRST PAGE link?
if($current_page > 2) {
$output .= "<a href="". $page_link ."?page=1/" title="First Page"><<</a>";
}

// Should we show the PREVIOUS PAGE link?
if($current_page > 1) {
$previous_page = $current_page - 1;
$output .= " <a href="". $page_link .">page=". $previous_page ."/" title="Previous Page"><</a>";
}

// Current Page Number
$output .= "<strong>[ ". $current_page ." ]</strong>";

// Should we show the NEXT PAGE link?
if($current_page < $this->pages) {
$next_page = $current_page + 1;
$output .= "<a href="". $page_link ."?page=". $next_page ."/" title="Next Page">></a>";
}

// Should we show the LAST PAGE link?
if($current_page < $this->pages - 1) {
$output .= " <a href="". $page_link ."?page=". $this->pages ."/" title="Last Page">>></a>";
}

// Return the output.
return $output;
}
}

$display = new display;
echo $display->pagination($row_counter, "2", "1", "http://theponther.peuplies.info/AAA%20TEST/Images/images3.php");
[/code]
×

Success!

Help @Peuplarchie 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.18,
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,
)...