Unstoppable Domains

Pagination help - 50NP$

Spaceship Spaceship
Watch

Ringr

VIP Member
Impact
45
Hey guys,

Well, the script below works 100% fine, but after it starts to load 100+ images (or however many are in the folder) it takes forever to load the whole page and eventually times out. This is not good.

Is there any way that the code below could be made so that only 20 images are displayed per page?

Code:
<? 
//get directory handle 
$hook = opendir("animals"); 

//start the table
echo "<table>\n";
echo "<tr>\n";

$counter = 0;

//read directory and echo list 
while (($file = readdir($hook)) !== false)
{
	if (($file !== ".")&&($file !== "..")) {
         // start a new row
         if ($counter == 5)
         {
               echo "</tr>\n<tr>\n";
			   $counter = 0;
         }

         echo "<td>\n<a href=\"aim:BuddyIcon?src=http://www.iming.org/imstuff/buddyicons/animals/$file\">\n<img src=\"http://www.iming.org/imsite/buddyicons/animals/$file\" border=0></a></td>\n";

         // add 1 to counter, or go back to 1
         $counter = $counter + 1;
	}
}        
         // need to fill up last row with empty columns
while ($counter < 5)
{
   echo "<td></td>\n";
   ++$counter;
}

// close row and table
echo "</tr>\n";
echo "</table>\n";


//set up full path 
$path = $location."/".$file; 

//check for directory 
if (is_dir($path)) 

//close directory 
closedir($hook); 
?>

NP$ will be rewarded to any individual that can help get this 'paginating' (or whatever the correct term be).

Thanks guys,
Andy
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Hey, if you do a quick google search, you will find tutorials on how to do this, here is one:

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

Instead of me just giving you the code, you may want to take a look at that tutorial so you can learn for future reference. If you need any help after reading the tutorial, let me know and I would be glad to help.
 
0
•••
I dont code php but wouldnt this work?
Code:
<? 
//get directory handle 
$hook = opendir("animals"); 

//start the table
echo "<table>\n";
echo "<tr>\n";

$counter = 0;

//read directory and echo list 
while (($file = readdir($hook)) !== false)
{
	if (($file !== ".")&&($file !== "..")) {
         if($counter == 20)
         {
              break;
          }
         // start a new row
         if ($counter == 5)
         {
               echo "</tr>\n<tr>\n";
			   $counter = 0;
         }

         echo "<td>\n<a href=\"aim:BuddyIcon?src=http://www.iming.org/imstuff/buddyicons/animals/$file\">\n<img src=\"http://www.iming.org/imsite/buddyicons/animals/$file\" border=0></a></td>\n";

         // add 1 to counter, or go back to 1
         $counter = $counter + 1;
	}
}        
         // need to fill up last row with empty columns
while ($counter < 5)
{
   echo "<td></td>\n";
   ++$counter;
}

// close row and table
echo "</tr>\n";
echo "</table>\n";


//set up full path 
$path = $location."/".$file; 

//check for directory 
if (is_dir($path)) 

//close directory 
closedir($hook); 
?>

I added the extra if statement. It checks if the counter is 20, if so breaks out of the loop.

Code:
         if($counter == 20)
         {
              break;
          }

Edit - Just looked again, its not counting to 20, you need a new variable

$countertotal = 0
increment that as well but do not reset to 0
then do the check on this variable.
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back