Jump to content

Display only X amount of images per page


iNko

Recommended Posts

Hi, i have a folder with thumbnails and original big pictures of the thumbnails, i wanna make it so that the max amount of thumbs that can be displayed on one page would be 3

 

<body>
<div id=head></div>
<div id=main>
<?php include("loadimages.php") ?> //<- here i take all the thumbnails that are in my thumb folder
</div>
<div id=foot></div>
</body>

 

i have 5 thumbnails, it displays all of them in the "main" div, i wanna add an "Next" and "Previous" buttons, i mean, i want it to show only 3 thumbs at one time, once u click "next" it would remove the first 3 thumbs and load the other 2 thumbnails..

 

heres a pic maybe it will explain better of what im trying to do..

29kopp2.png

Link to comment
Share on other sites

Pagination is a pain in the ass sometimes but basically what you need is to set variables for current page, number of photos to show, current page offset (if not the first page) etc.

Reading some tutorials will give you an idea.

In your case it looks like you will access a second php file making it more complicated.

The tutorials rarely bring that up but you might have to use get-variables and urlencode/urldecode if there is any criteria that plays part in showing those particular thumbs (whether it's search terms or user or anything else).

 

It's a lot of work and you might get somewhere faster if you try it yourself first and mail us where and when you get stuck.

 

Link to comment
Share on other sites

show us loadimages.php

 

if you ARE placing your images in an array, this may help http://hub.lotsofcode.com/php-array-pagination/

 

this is my loadimages.php:

<?php
$dir = "uploads/thumbs/watermarkedthumbs/";
$file_display = array ('jpg', 'jpeg', 'png', 'gif');

if (file_exists($dir) == false) {
echo 'tt';
} else {
$dir_contents = scandir($dir);

foreach ($dir_contents as $file) {
$file_type = strtolower(end(explode('.', $file)));

if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) {

echo '<img style="border:thin solid #FFF;margin-top:10px;margin-left:10px;margin-right:10px" src="', $dir, '/', $file, '" alt="', $file, '" />';
}

}
}

 

should i try to modify my loadimages.php file with these codes?:

 

foreach (range(1, 100) as $value) {
  $products[] = array(
  'Product' => 'Product '.$value,
  'Price' => rand(100, 1000),
  );
}

 

and

 

if (count($products)) {
    // Create the pagination object
    $pagination = new pagination($products, (isset($_GET['page']) ? $_GET['page'] : 1), 15);
    // Parse through the pagination class
    $productPages = $pagination->getResults();
    // If we have items 
    if (count($productPages) != 0) {
        // Create the page numbers
        echo $pageNumbers = '<div class="numbers">'.$pagination->getLinks().'</div>';
        // Loop through all the items in the array
        foreach ($productPages as $productArray) {
            // Show the information about the item
            echo '<p><b>'.$productArray['Product'].'</b>   £'.$productArray['Price'].'</p>';
        }
        // print out the page numbers beneath the results
        echo $pageNumbers;
    }
}

 

?>

 

 

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.