Jump to content

Creating page numbers for image gallery.


peuge

Recommended Posts

Wassup all?

 

I have an image gallery with a thumbnail table to the left side of the large picture. The pictures are dumped in their respective category folder and there is a category table on the right of the large picture. All works well, but now I want to be able to add more pictures and need 1,2,3,4 etc for the next page so it does not display all the thumbs.

 

My problem now is that I want to display 10 pictures for each thumbnail page.

So far I have this

function display_thumbs($images,$cat,$big,$page){
$cols = 2;
$page_num=$page;
$amnt = ($page*10);
$i=-1;
if ($handle = opendir($images.$cat)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != ".." && $file != rtrim($big,"/") && $i >= ($amnt-9) && $i <= $amnt) {			    
          $files[] = $file;									
       }
		 $i++;	

   }
   closedir($handle);
} 
$colCtr = 0;
echo '<table id="thumbstable"><tr>';
foreach($files as $file)
{

 

There is more to the function but that part works. Right now I am only getting it to display about 9 pics on the first page, this then goes to ten, then eleven etc for each next page. I have a whole lot of different combinations of $i etc but cant seem to get it.

 

$images,$cat,$big,$page

 

The first three are just the directory names, the last $page is the page number selected (which starts from 1) Any help is much appreciated.

 

Thanks in advance

Link to comment
Share on other sites

Looked over that, thanks. But im not using mySQL with this and cannot seem to figure it out?

 

So after some other searhing I found something along the lines of this (which does not work either) :)

 

$amnt = ($page*10);
$limit=0;
$i=0;
$brk=1;
if ($handle = opendir($images.$cat)) {   
   while (false !== ($file = readdir($handle)) && $brk!=0 ) {
       if ($file != "." && $file != ".." && $file != rtrim($big,"/") && $i > $amnt-10) {			    
            $files[] = $file;										
       }

       $limit++;																
       $i++;		

       if ($limit==10){
          $brk=0;
       } 

		  
   }
   closedir($handle);
} 

 

Thanks again

 

EDIT: Sorry the output gives me 7 pics for the first page, but gives an error on the next pages.

 

Warning: Invalid argument supplied for foreach() in functions.php on line 177

 

That code just displays the pics so its obviously not picking up the pics.

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.