How to display paging(using flat files)?

  • pepsidemon
  • Newbie
  • Newbie
  • pepsidemon
  • Posts: 10

Post 3+ Months Ago

I wanted to display paging like: <<first|1|2|3|4|5|...>>

I know i can do it with an SQL database,but I want to use flat files.How would I go about doing this?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • pepsidemon
  • Newbie
  • Newbie
  • pepsidemon
  • Posts: 10

Post 3+ Months Ago

Jeez...I've been looking forever and can't find a thing.
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Ok, if you won't use SQL, which I guess you mean any server-side scripting, how are you planning doing that.

If you have plain HTML files only, there is only way of doing that: hardcoding the "index" in every HTML file.

For an automated solution without server-side script, I guess you can try using javascript to writting the index in the HTML file. You will have to update the numbers of files in the script as you add them. And you will have to include the script in every HTML file.
  • pepsidemon
  • Newbie
  • Newbie
  • pepsidemon
  • Posts: 10

Post 3+ Months Ago

Ok,I am trying to create a gallery.for the page thumbnails.php,i wanted to have the page display thing.I found a gallery script that uses it.I can put the code up if you want me to.
  • pepsidemon
  • Newbie
  • Newbie
  • pepsidemon
  • Posts: 10

Post 3+ Months Ago

Here is the other gallery's(i don't know where to start):
Code: [ Select ]
<?php
## Admin options - edit as you wish
# Allow admin area? 1=yes, 0=no
$adminarea = 1;
# Enter the password you want for the administator
$adminpassword = "cookiemoth";
# Do you want to have maximum file sizes, 1 = yes, 0 = no
$filesizes = 0;
# If you answered 1 to the above please fill in the below (in KB)
$maxthumbfilesize = "20";
$maximagefilesize = "400";
# Enter what should be the begining of all your thumbs, ie "tn_"
$key = "tn_";
##########################################
## Format Variables, edit if you want!! ##
##########################################
# Enter the Name of your image gallery, i.e DBZ Gallery
$galleryname = "My Dog";

## Image variables
# Enter how many images you want to be displayed per page
$limit = 15;
##################

# font face, font size(in points), font color, link color,
$fontface = "arial";
$fontsize = 8;
$fontcolor = "666666";
$linkcolor = "666666";

## Table variables
# Enter the border size in pixels and the border color in hex
$border=1;
$bordercolor="666666";
# enter how wide in px you want the space around the image to be
$cellpadding = 2;
# Enter how many columns in the table you want there to be before
# It starts a new row
$columns=5;
# Now enter the bg of the table
$tablebg="cccccc";
# Now the width of the table
$tablewidth = "600";
#################


##########################################
## Pretty Complicated Leave alone!!!! ##
##########################################

    if(phpversion()>4.2){
     $HTTP_HOST = $_SERVER["$HTTP_HOST"];
     $postpassword = $_POST["postpassword"];
    }

include("header.inc");
    if($view){
     echo "<table cellpadding=\"$cellpadding\" cellspacing=\"$border\" bgcolor=\"#$bordercolor\" style=\"font-size: ${fontsize}pt; color: #$fontcolor; font-family: $fontface\" width=\"$tablewidth\">";
        if(!file_exists($view)){
         echo "<tr bgcolor=\"$tablebg\"><td>The file does not exist</td></tr>";
        } else {
         $imagesize = getimagesize($view);
         $stamp = filemtime($view);
         $filesize = filesize($view);
         $filesize = number_format($filesize/1024,"2",".","'");
         $date = date("dS of F, Y \@ H:i",$stamp);
         echo "<tr bgcolor=\"$tablebg\"><td align=\"center\"><img src=\"$view\"></td></tr>";
         echo "<tr><td align=\"center\"><font color=\"$tablebg\"><b>Image Details</b></font></td></tr>";
         echo "<tr bgcolor=\"$tablebg\"><td><b>File Name:</b> /$view<br><b>Width:</b> $imagesize[0] pixels<br>\n<b>Height:</b> $imagesize[1] pixels<br><b>File Size:</b> $filesize KB<br><b>Uploaded:</b> $date</td></tr>";
        }
     echo "</table>";
    } else {
        if(!$page){
         $page=1;
        }
        if(!$reverse){
         $reverse="no";
        }
        if(!$sort){
         $sort="abc";
        }
     $page -= 1;
     $page *= $limit;
        function getaccess ($file) {
         $stamp = filemtime($file);
         return $stamp;
        }
            while ($file = readdir($directory)) {
                if (is_dir($dir.$slash.$file) || (strtolower(substr($file, 0,3)) == $key && (strstr($file, ".gif") || strstr($file, ".jpg") || strstr($file, ".png") || strstr($file, ".bmp") || strstr($file, ".jpeg")) ) ) {
                    if($file != ".." && $file != "."){
                        if($sort=="date"){
                         $stamp = getaccess($dir.$slash.$file);
                         $array .= "$stamp||$file||\n";
                        } else {
                         $lowercase = strtolower($file);
                            if(is_dir($dir.$slash.$file)){
                             $array .= "_00_$lowercase||$file||\n";
                            } else {
                             $imagecount++;
                             $array .= "$lowercase||$file||\n";
                            }
                        }
                    }
                }
            }
     closedir($directory);
     $array = substr($array, 0,-1);
     $files = explode("\n", $array);
     echo "
    <body text=\"$fontcolor\" link=\"$linkcolor\" vlink=\"$linkcolor\" style=\"font-family: $fontface\">
    <table cellpadding=\"$cellpadding\" cellspacing=\"$border\" bgcolor=\"#$bordercolor\" style=\"font-size: ${fontsize}pt; color: #$fontcolor\" width=\"$tablewidth\">";
        if($message){
         echo " <tr bgcolor=\"$tablebg\">\n <td colspan=\"$columns\">\n  $message\n </td>\n </tr>\n";
        }
        if(!$imagecount){
         $imagecount=0;
        }
    echo " <tr>
     <td bgcolor=\"$tablebg\" colspan=\"$columns\">
      <b>Total Images:</b> $imagecount<br>\n<b>Go to Page:</b> ";
        for ($i = 1; $i <= count($files); $i+=$limit) {
            if (!$files[$i]) {
              continue;
            }
         $a++;
         echo "  <a href=\"$PHP_SELF?page=$a&sort=$sort&dir=$dir\">$a</a> \n";
        }
     $newpage = $page + 1;
     echo " </td>
     </tr>
     <tr>
     <td bgcolor=\"$tablebg\" colspan=\"$columns\">
      <b>Sort:</b> Filename: <a href=\"$PHP_SELF?page=$newpage&sort=abc&reverse=no&dir=$dir\">Ascending</a> <a href=\"$PHP_SELF?page=$newpage&sort=abc&reverse=yes&dir=$dir\">Descending</a> | Date: <a href=\"$PHP_SELF?page=$newpage&sort=date&reverse=no&dir=$dir\">Ascending</a> <a href=\"$PHP_SELF?page=$newpage&sort=date&reverse=yes&dir=$dir\">Descending</a>
     </td>
     </tr>
     <tr bgcolor=\"$tablebg\">\n";
        if($sort=="abc"){
            if($reverse=="yes"){
             rsort($files, SORT_STRING);
            } else {
             sort($files, SORT_STRING);
            }
        } else {
            if($reverse=="yes"){
             rsort($files, SORT_NUMERIC);
            } else {
             sort($files, SORT_NUMERIC);
            }
        }
    
        for ($i = $page; $i < $page+$limit; $i++) {
            if (!$files[$i]) {
              continue;
            }
         $cols++;
         $image = explode("||",$files[$i]);
         $link = $PHP_SELF."?view=".$dir.$slash.eregi_replace($key,"",$image[1])."\" target=\"$image[1]";
     unset($deletelink);
     $dirtest = ereg_replace("_00_","",$image[1]);
        if($adminarea==1 && !$loginerror){
            if(!is_dir($dir.$slash.$dirtest)){
             $deletelink = "<br><a href=\"$PHP_SELF?delete=$dir$slash$image[1]\">[delete]</a>";
            }
        }
        if($dir){
         $image[1] = "$dir/".$image[1];
        }
     unset($dirtitle);
        if(is_dir($dir.$slash.$dirtest)){
         $image = "folder.gif\" width=\"45";
         $link = "$PHP_SELF?dir=$dir$slash$dirtest";
         $dirtitle = "<br>$dirtest";
        } else {
         $image = $image[1];
        }
         echo " <td align=\"center\"><a href=\"$link\"><img src=\"$image\" border=\"0\">$dirtitle</a>$deletelink</td>\n";
            if($cols==$columns && ($i+1) != ($page+$limit)){
             echo " </tr>\n <tr bgcolor=\"$tablebg\">\n";
             $cols=0;
            }
        }
        if($adminarea==1){
            if($loginerror){
             echo "<tr bgcolor=\"$tablebg\"><form action=\"$PHP_SELF?loginsubmit=yes\" method=\"post\"><td colspan=\"$columns\" align=\"center\"><B>Login</B><br>Password: <input type=\"password\" name=\"postpassword\"> <input type=\"submit\" value=\"Login\"></td></form></tr>";
            } else {
             echo "<tr bgcolor=\"$tablebg\"><form action=\"$PHP_SELF?upload=yes&dir=$dir\" method=\"post\" enctype=\"multipart/form-data\"><td colspan=\"$columns\" align=\"center\"><B>Admin: Upload an image</B><br>Thumbnail: <input type=\"file\" name=\"postthumbnail\"><br>Full Size Images: <input type=\"file\" name=\"postimage\"><br><input type=\"submit\" value=\"Upload\">";
                if($dir){
                 echo "<br>If you plan on uploading to this directory you will need to chmod it to 777";
                }
             echo "</td></form></tr>";
            }
        }
     echo " </tr>\n <tr>\n <td colspan=\"$columns\" bgcolor=\"$tablebg\">\n Image Gallery v.3.0 created by Deano of <a href=\"http://www.naget.com\">NAGET Solutions</a><br><a href=\"$PHP_SELF\">Back to image Index</a>\n </td>\n </tr>\n";
     echo "</table>\n";
    }
include("footer.inc");
?>
  1. <?php
  2. ## Admin options - edit as you wish
  3. # Allow admin area? 1=yes, 0=no
  4. $adminarea = 1;
  5. # Enter the password you want for the administator
  6. $adminpassword = "cookiemoth";
  7. # Do you want to have maximum file sizes, 1 = yes, 0 = no
  8. $filesizes = 0;
  9. # If you answered 1 to the above please fill in the below (in KB)
  10. $maxthumbfilesize = "20";
  11. $maximagefilesize = "400";
  12. # Enter what should be the begining of all your thumbs, ie "tn_"
  13. $key = "tn_";
  14. ##########################################
  15. ## Format Variables, edit if you want!! ##
  16. ##########################################
  17. # Enter the Name of your image gallery, i.e DBZ Gallery
  18. $galleryname = "My Dog";
  19. ## Image variables
  20. # Enter how many images you want to be displayed per page
  21. $limit = 15;
  22. ##################
  23. # font face, font size(in points), font color, link color,
  24. $fontface = "arial";
  25. $fontsize = 8;
  26. $fontcolor = "666666";
  27. $linkcolor = "666666";
  28. ## Table variables
  29. # Enter the border size in pixels and the border color in hex
  30. $border=1;
  31. $bordercolor="666666";
  32. # enter how wide in px you want the space around the image to be
  33. $cellpadding = 2;
  34. # Enter how many columns in the table you want there to be before
  35. # It starts a new row
  36. $columns=5;
  37. # Now enter the bg of the table
  38. $tablebg="cccccc";
  39. # Now the width of the table
  40. $tablewidth = "600";
  41. #################
  42. ##########################################
  43. ## Pretty Complicated Leave alone!!!! ##
  44. ##########################################
  45.     if(phpversion()>4.2){
  46.      $HTTP_HOST = $_SERVER["$HTTP_HOST"];
  47.      $postpassword = $_POST["postpassword"];
  48.     }
  49. include("header.inc");
  50.     if($view){
  51.      echo "<table cellpadding=\"$cellpadding\" cellspacing=\"$border\" bgcolor=\"#$bordercolor\" style=\"font-size: ${fontsize}pt; color: #$fontcolor; font-family: $fontface\" width=\"$tablewidth\">";
  52.         if(!file_exists($view)){
  53.          echo "<tr bgcolor=\"$tablebg\"><td>The file does not exist</td></tr>";
  54.         } else {
  55.          $imagesize = getimagesize($view);
  56.          $stamp = filemtime($view);
  57.          $filesize = filesize($view);
  58.          $filesize = number_format($filesize/1024,"2",".","'");
  59.          $date = date("dS of F, Y \@ H:i",$stamp);
  60.          echo "<tr bgcolor=\"$tablebg\"><td align=\"center\"><img src=\"$view\"></td></tr>";
  61.          echo "<tr><td align=\"center\"><font color=\"$tablebg\"><b>Image Details</b></font></td></tr>";
  62.          echo "<tr bgcolor=\"$tablebg\"><td><b>File Name:</b> /$view<br><b>Width:</b> $imagesize[0] pixels<br>\n<b>Height:</b> $imagesize[1] pixels<br><b>File Size:</b> $filesize KB<br><b>Uploaded:</b> $date</td></tr>";
  63.         }
  64.      echo "</table>";
  65.     } else {
  66.         if(!$page){
  67.          $page=1;
  68.         }
  69.         if(!$reverse){
  70.          $reverse="no";
  71.         }
  72.         if(!$sort){
  73.          $sort="abc";
  74.         }
  75.      $page -= 1;
  76.      $page *= $limit;
  77.         function getaccess ($file) {
  78.          $stamp = filemtime($file);
  79.          return $stamp;
  80.         }
  81.             while ($file = readdir($directory)) {
  82.                 if (is_dir($dir.$slash.$file) || (strtolower(substr($file, 0,3)) == $key && (strstr($file, ".gif") || strstr($file, ".jpg") || strstr($file, ".png") || strstr($file, ".bmp") || strstr($file, ".jpeg")) ) ) {
  83.                     if($file != ".." && $file != "."){
  84.                         if($sort=="date"){
  85.                          $stamp = getaccess($dir.$slash.$file);
  86.                          $array .= "$stamp||$file||\n";
  87.                         } else {
  88.                          $lowercase = strtolower($file);
  89.                             if(is_dir($dir.$slash.$file)){
  90.                              $array .= "_00_$lowercase||$file||\n";
  91.                             } else {
  92.                              $imagecount++;
  93.                              $array .= "$lowercase||$file||\n";
  94.                             }
  95.                         }
  96.                     }
  97.                 }
  98.             }
  99.      closedir($directory);
  100.      $array = substr($array, 0,-1);
  101.      $files = explode("\n", $array);
  102.      echo "
  103.     <body text=\"$fontcolor\" link=\"$linkcolor\" vlink=\"$linkcolor\" style=\"font-family: $fontface\">
  104.     <table cellpadding=\"$cellpadding\" cellspacing=\"$border\" bgcolor=\"#$bordercolor\" style=\"font-size: ${fontsize}pt; color: #$fontcolor\" width=\"$tablewidth\">";
  105.         if($message){
  106.          echo " <tr bgcolor=\"$tablebg\">\n <td colspan=\"$columns\">\n  $message\n </td>\n </tr>\n";
  107.         }
  108.         if(!$imagecount){
  109.          $imagecount=0;
  110.         }
  111.     echo " <tr>
  112.      <td bgcolor=\"$tablebg\" colspan=\"$columns\">
  113.       <b>Total Images:</b> $imagecount<br>\n<b>Go to Page:</b> ";
  114.         for ($i = 1; $i <= count($files); $i+=$limit) {
  115.             if (!$files[$i]) {
  116.               continue;
  117.             }
  118.          $a++;
  119.          echo "  <a href=\"$PHP_SELF?page=$a&sort=$sort&dir=$dir\">$a</a> \n";
  120.         }
  121.      $newpage = $page + 1;
  122.      echo " </td>
  123.      </tr>
  124.      <tr>
  125.      <td bgcolor=\"$tablebg\" colspan=\"$columns\">
  126.       <b>Sort:</b> Filename: <a href=\"$PHP_SELF?page=$newpage&sort=abc&reverse=no&dir=$dir\">Ascending</a> <a href=\"$PHP_SELF?page=$newpage&sort=abc&reverse=yes&dir=$dir\">Descending</a> | Date: <a href=\"$PHP_SELF?page=$newpage&sort=date&reverse=no&dir=$dir\">Ascending</a> <a href=\"$PHP_SELF?page=$newpage&sort=date&reverse=yes&dir=$dir\">Descending</a>
  127.      </td>
  128.      </tr>
  129.      <tr bgcolor=\"$tablebg\">\n";
  130.         if($sort=="abc"){
  131.             if($reverse=="yes"){
  132.              rsort($files, SORT_STRING);
  133.             } else {
  134.              sort($files, SORT_STRING);
  135.             }
  136.         } else {
  137.             if($reverse=="yes"){
  138.              rsort($files, SORT_NUMERIC);
  139.             } else {
  140.              sort($files, SORT_NUMERIC);
  141.             }
  142.         }
  143.     
  144.         for ($i = $page; $i < $page+$limit; $i++) {
  145.             if (!$files[$i]) {
  146.               continue;
  147.             }
  148.          $cols++;
  149.          $image = explode("||",$files[$i]);
  150.          $link = $PHP_SELF."?view=".$dir.$slash.eregi_replace($key,"",$image[1])."\" target=\"$image[1]";
  151.      unset($deletelink);
  152.      $dirtest = ereg_replace("_00_","",$image[1]);
  153.         if($adminarea==1 && !$loginerror){
  154.             if(!is_dir($dir.$slash.$dirtest)){
  155.              $deletelink = "<br><a href=\"$PHP_SELF?delete=$dir$slash$image[1]\">[delete]</a>";
  156.             }
  157.         }
  158.         if($dir){
  159.          $image[1] = "$dir/".$image[1];
  160.         }
  161.      unset($dirtitle);
  162.         if(is_dir($dir.$slash.$dirtest)){
  163.          $image = "folder.gif\" width=\"45";
  164.          $link = "$PHP_SELF?dir=$dir$slash$dirtest";
  165.          $dirtitle = "<br>$dirtest";
  166.         } else {
  167.          $image = $image[1];
  168.         }
  169.          echo " <td align=\"center\"><a href=\"$link\"><img src=\"$image\" border=\"0\">$dirtitle</a>$deletelink</td>\n";
  170.             if($cols==$columns && ($i+1) != ($page+$limit)){
  171.              echo " </tr>\n <tr bgcolor=\"$tablebg\">\n";
  172.              $cols=0;
  173.             }
  174.         }
  175.         if($adminarea==1){
  176.             if($loginerror){
  177.              echo "<tr bgcolor=\"$tablebg\"><form action=\"$PHP_SELF?loginsubmit=yes\" method=\"post\"><td colspan=\"$columns\" align=\"center\"><B>Login</B><br>Password: <input type=\"password\" name=\"postpassword\"> <input type=\"submit\" value=\"Login\"></td></form></tr>";
  178.             } else {
  179.              echo "<tr bgcolor=\"$tablebg\"><form action=\"$PHP_SELF?upload=yes&dir=$dir\" method=\"post\" enctype=\"multipart/form-data\"><td colspan=\"$columns\" align=\"center\"><B>Admin: Upload an image</B><br>Thumbnail: <input type=\"file\" name=\"postthumbnail\"><br>Full Size Images: <input type=\"file\" name=\"postimage\"><br><input type=\"submit\" value=\"Upload\">";
  180.                 if($dir){
  181.                  echo "<br>If you plan on uploading to this directory you will need to chmod it to 777";
  182.                 }
  183.              echo "</td></form></tr>";
  184.             }
  185.         }
  186.      echo " </tr>\n <tr>\n <td colspan=\"$columns\" bgcolor=\"$tablebg\">\n Image Gallery v.3.0 created by Deano of <a href=\"http://www.naget.com\">NAGET Solutions</a><br><a href=\"$PHP_SELF\">Back to image Index</a>\n </td>\n </tr>\n";
  187.      echo "</table>\n";
  188.     }
  189. include("footer.inc");
  190. ?>



Mine:
Code: [ Select ]
<? for ($i=1; file_exists("images/image".strval($i).".jpg"); $i++) {
$a=getimagesize("images/image".strval($i).".jpg");
$i=strval($i);
echo "<td width=\"".strval($a[0])."\"><a href=preview.php?i=$i target=pre><img border=0 width=100 height=100 src=images/image$i.jpg></a></td>";


?>
  1. <? for ($i=1; file_exists("images/image".strval($i).".jpg"); $i++) {
  2. $a=getimagesize("images/image".strval($i).".jpg");
  3. $i=strval($i);
  4. echo "<td width=\"".strval($a[0])."\"><a href=preview.php?i=$i target=pre><img border=0 width=100 height=100 src=images/image$i.jpg></a></td>";
  5. ?>
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

mmm... sorry, I won't read the whole script (the first). You should try it, but if it does not work, you better write your own.

Let's say you send page=3 as parameter to get page 3
Code: [ Select ]
<?

$start = ($page-1) * 20;

for ($i=$start;
  (file_exists("images/image".strval($i).".jpg")) && ($i < ($start+20));
  $i++) {

  $a=getimagesize("images/image".strval($i).".jpg");
  $i=strval($i);
  echo "<td width=\"".strval($a[0])."\"><a href=preview.php?i=$i target=pre><img border=0 width=100 height=100 src=images/image$i.jpg></a></td>";
}

if ($i >= ($start+20)) {
  print("<a href=\"file.php?page=".$page+1."\">Next page</a>");
}
if ($page > 1) {
  print("<a href=\"file.php?page=".$page-1."\">Previous page</a>");
}

?>
  1. <?
  2. $start = ($page-1) * 20;
  3. for ($i=$start;
  4.   (file_exists("images/image".strval($i).".jpg")) && ($i < ($start+20));
  5.   $i++) {
  6.   $a=getimagesize("images/image".strval($i).".jpg");
  7.   $i=strval($i);
  8.   echo "<td width=\"".strval($a[0])."\"><a href=preview.php?i=$i target=pre><img border=0 width=100 height=100 src=images/image$i.jpg></a></td>";
  9. }
  10. if ($i >= ($start+20)) {
  11.   print("<a href=\"file.php?page=".$page+1."\">Next page</a>");
  12. }
  13. if ($page > 1) {
  14.   print("<a href=\"file.php?page=".$page-1."\">Previous page</a>");
  15. }
  16. ?>


Well, it is not the complete solution, but I think you can keep working on it.
  • pepsidemon
  • Newbie
  • Newbie
  • pepsidemon
  • Posts: 10

Post 3+ Months Ago

heh,i pulled the part from the script that i need.I am just trying to put it into mine.
  • pepsidemon
  • Newbie
  • Newbie
  • pepsidemon
  • Posts: 10

Post 3+ Months Ago

i still don't get this...
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Ok, the script I've posted was not tested. The concept is you have an unknown number of files in disk. You call your script which reads files starting in (20 x page) and stops if no more files are found or 20 files were printed. Then, if there was more than 20 in disk, it activates the Next page link. If the page is greater than 1 it activates the Previous page link.

If you click on Next page link, the script will recieve the page variable with a number (ie: 4) and will calculate 20 x 4 = 80, then will start the for() loop in 80.JPG up to 100.JPG it it exists...
  • pepsidemon
  • Newbie
  • Newbie
  • pepsidemon
  • Posts: 10

Post 3+ Months Ago

i keep on getting parse errors.
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Ok, you can test this PHP file at http://www.drk.com.ar/public/paging.php

Code: [ Select ]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>PAGING by DRK ;)</title>
</head>

<body>
<table>
<?
error_reporting(E_ALL);

// The variable $page will be recieved as the page number to show
// This script will make a new page every $max_per_page images
$max_per_page = 3;

// Get the page parameter
$page = (isset($_GET['page'])) ? $_GET['page'] : 1;

// Calculate the number of the first image to show for $page
$start = (($page-1) * $max_per_page) + 1;

// Browse the directory and stop on $max_per_page or file not found
for ($i=$start;
  ((file_exists("image$i.jpg")) && ($i < ($start+$max_per_page)));
  $i++) {

  $a = getimagesize("image".$i.".jpg");
  $i = strval($i);
    
    // Print HTML for this image
  echo "<tr><td width=\"".$a[0]."\"><a href=\"/\"><img border=0 width=\"".$a[0]."\" height=\"".$a[1]."\" src=\"image$i.jpg\"></a></td></tr>";
}
?>
</table>
<br>
<?
// If we reached the $max_per_page, there should be a next page
if ($i >= ($start+$max_per_page)) {
  print("<a href=\"paging.php?page=".($page+1)."\">Next page</a>");
}

// If this is not the first page, there must be a previous page
if ($page > 1) {
  print("<a href=\"paging.php?page=".($page-1)."\">Previous page</a>");
}

?>
</body>
</html>
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.     <title>PAGING by DRK ;)</title>
  5. </head>
  6. <body>
  7. <table>
  8. <?
  9. error_reporting(E_ALL);
  10. // The variable $page will be recieved as the page number to show
  11. // This script will make a new page every $max_per_page images
  12. $max_per_page = 3;
  13. // Get the page parameter
  14. $page = (isset($_GET['page'])) ? $_GET['page'] : 1;
  15. // Calculate the number of the first image to show for $page
  16. $start = (($page-1) * $max_per_page) + 1;
  17. // Browse the directory and stop on $max_per_page or file not found
  18. for ($i=$start;
  19.   ((file_exists("image$i.jpg")) && ($i < ($start+$max_per_page)));
  20.   $i++) {
  21.   $a = getimagesize("image".$i.".jpg");
  22.   $i = strval($i);
  23.     
  24.     // Print HTML for this image
  25.   echo "<tr><td width=\"".$a[0]."\"><a href=\"/\"><img border=0 width=\"".$a[0]."\" height=\"".$a[1]."\" src=\"image$i.jpg\"></a></td></tr>";
  26. }
  27. ?>
  28. </table>
  29. <br>
  30. <?
  31. // If we reached the $max_per_page, there should be a next page
  32. if ($i >= ($start+$max_per_page)) {
  33.   print("<a href=\"paging.php?page=".($page+1)."\">Next page</a>");
  34. }
  35. // If this is not the first page, there must be a previous page
  36. if ($page > 1) {
  37.   print("<a href=\"paging.php?page=".($page-1)."\">Previous page</a>");
  38. }
  39. ?>
  40. </body>
  41. </html>


It is working now, and it is a good example of what you need. It's a simpler one too.
You will have to undestand it and make the changes you may want in order to get the paging like 1, 2, 3, 4 >>
  • pepsidemon
  • Newbie
  • Newbie
  • pepsidemon
  • Posts: 10

Post 3+ Months Ago

Awesome.It works! Thanks SO much

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 96 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.