...

View Full Version : Pagination problem with listing directory result



Peuplarchie
08-06-2007, 01:45 PM
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.








<?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>\n\n\n";

++$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";
?>





Thanks !

Fumigator
08-06-2007, 06:13 PM
Try using Firepage's pagination script. You can have it up and working in about 10 minutes.

www.firepages.com.au

Peuplarchie
08-06-2007, 06:44 PM
thanks but I can't use db.

Fumigator
08-06-2007, 07:58 PM
I adapted the Firepage script to page through icon files in a directory-- no database involved.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum