Split result in different page if more than...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Split result in different page if more than...

Post 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 !
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

Have look at

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

Is this what you need?
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Post 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 ?
Post Reply