php pagination problem

mlowe.space12

New Member
Messages
5
Reaction score
0
Points
1
I got this pagination thing from this forum but there are a few errors. it comes up with First | Last | Last | Last | Last | Last | and i need it to display in 2 columns
here is the code:

PHP Code:
PHP:
<?php 
if(!$_GET['start']) { 
$start = 0; 
} else { 
$start = $_GET['start']; 
} 
$exclude_files = array(""); 
$ifiles = Array(); 
$handle = opendir('upload/'); 
$number_to_display = '10'; 
while (false !== ($file = readdir($handle))) { 
   if ($file != "." && $file != ".." && !in_array($file, $exclude_files)) {     
       $ifiles[] = $file; 
   } 
} 
closedir($handle); 

$total_files = count($ifiles); 
$req_pages = ceil($total_files/$number_to_display); 

echo "Total Images = ". $total_files."<br>"; 


   for($z=0; $z<$number_to_display; $z++) { 
      $vf = $z+$start; 
       $ifiles_display = explode(".", $ifiles[$vf]); 
      echo "<img width=200 height=200 src =upload/" . $ifiles[$vf]. "></img>"; 
  echo '<br>'; 

} 
echo "<a href=\"?start=0\">First</a> |"; 
   for($x=1; $x<$req_pages; $x++) { ?> 
<a href="?start=<?php echo ($x)*$number_to_display; ?>">Last</a> | 

<?php } ?>
 

bdistler

Well-Known Member
Prime Account
Messages
3,534
Reaction score
196
Points
63
Be sure the files are 'img' type
set $workDir
This displays in one column
use HTML and CSS for more columms

PHP:
<?php
// program => test_pagination.php <=

$exclude_files = array("");
$ifiles = Array();
$number_to_display = '10';
$workDir = 'test';

if(!$_GET['start'])
  {
    $start = 0;
  }
  else
    {
      $start = $_GET['start'];
    }

$handle = opendir($workDir);

while (FALSE !== ($file = readdir($handle)))
  {
   if ($file != "." && $file != ".." && !in_array($file, $exclude_files))
    {
      // replace space in file name with "%20" else 'src = ' will stop at first
      // space for file name
      $file = str_ireplace(" ", "%20", $file);

      $ifiles[] = $file;
    }
  }

closedir($handle);

$total_files = count($ifiles);
$req_pages = ceil($total_files/$number_to_display);

print "Total files = ". $total_files."<br>\n";
print "$req_pages pages at $number_to_display max per page<br>\n";
print "Start at #" . ($start + 1) . "<br>\n";

$temp = $start + $number_to_display;

if ($temp > $total_files)
  {
    $next_number_to_display = $total_files - $start;
  }
  else
    {
      $next_number_to_display = $number_to_display;
    }

print "Number to show = " . $next_number_to_display . "<br>\n";

for($z=0; $z<$next_number_to_display; $z++)
  {
    $vf = $z+$start;
    print "<img width=100 height=100 src = $workDir/$ifiles[$vf]>" . ($vf + 1) . "</img><br>\n<br>\n";
  }

print "<a href=\"?start=0\">First start 1</a> | \n";

for($x=1; $x < $req_pages - 1; $x++)
  {
    $temp = $x * $number_to_display;
    print "<a href=\"?start=$temp\">Next $number_to_display start at " . ($temp + 1) . "</a> | \n";
  }

$temp = $temp + $number_to_display;
$y = $total_files - ($x * $number_to_display);

print "<a href=\"?start=$temp\">Last $y start at " . ($temp + 1) . "</a>";

?>
 
Top