Page 1 of 1

Split result in different page if more than...

Posted: Sun Aug 05, 2007 3:43 pm
by Peuplarchie
Good day to you all,
The below code search for image in a directory and show them in row of 5.

Code: Select all

<?php
$image_counter = 3;
$row_counter = 0;
$cell_counter = 0;
$show=array('.jpg','.JPG','.gif','.GIF');
$path = './images/';
$dir_handle = @opendir($path) or die("Unable to open $path");
$image_table = "<table>\n<tr><th colspan=5>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 + 2) % 5)){
          $row_counter++;
        }
      $image_table .=(($image_counter + 2) % 5)? "" : "</tr>\n<tr>";
      $image_table .= "\n<td><img src=\"$path$file\"><br>$file</td>\n";
      ++$image_counter;
      ++$cell_counter;
  }

}
$colspan= ($row_counter * 5) - $cell_counter;
$image_table .= ($cell_counter % 5) ?  "<td colspan=$colspan>&nbsp;</td>" : "";
$image_table .= "</tr>\n</table>\n";
echo "$image_table<br><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";
?>
My question is if the code find lets say 100 image, how can I split the result in page of 5 row ?

Thanks !

Posted: Sun Aug 05, 2007 6:50 pm
by thiscatis
Have look at

http://www.phpfreaks.com/tutorials/43/0.php

Is this what you need?

Posted: Sun Aug 05, 2007 6:59 pm
by Peuplarchie
Something very similar to this , yes.
In my case I don't use a database I'm reading a directory.
Can it still be done ?