Glitter Pic
Glitter Pic

Reputation: 1

Pagination on php foreach loop by this image editor

help by foreach pagination php i have this code:

/*loop trough folders and show images from each folder*/
foreach ($folders as $folderNames2) {

?>
<div class="sEditorEffectsSampleImages" id="<?php echo $folderNames2; ?>List">
    <?php

    //list images from each folder
    /*search .png files in each folder andd create effect list form png names*/
    $files = glob($settingsValue['effectsFolder'] . '/' . $folderNames2 . '/*.png');
    /*if there is images in folder list them*/
    if (count($files > 0)){
    ?>

    <?php
    /*loop trough each folder and outpu image names*/

    foreach ($files as $name) {
        $path = explode('/', $name);
        $name = explode('.', $path[2]);
        //echo '<li id="'.$name[0].'" idf="'.$folderNames.'"><a href="#">'.$name[0].'</a></li>';
        //echo $name[0]."|";

        ?>
        <div class="imageEffectSampleImageHodlder" sEffect="<?php echo $name[0]; ?>"
             sEffectCategory="<?php echo $folderNames2; ?>"><img
                src="<?php echo $settingsValue['effectsFolder'] . '/' . $folderNames2 . '/' . $name[0] . '.png'; ?>"/>

            <p> <?php echo $name[0]; ?></p></div>
    <?php
    }/*for each image loop*/
    ?>

<?php
}/*if count $files is bigger then zero*/

?>

http://www.klick-bild.net/framegen/upload/images/Unbenannt.png

for example, the red box is how I imagine it (I added with paint) whoever can kindly help me

thank you

Upvotes: 0

Views: 1506

Answers (1)

Michael Wheeler
Michael Wheeler

Reputation: 660

Generally with pagination you'll need to use $_GET to determine what to show on a certain page. It can be as simple or complex and you want to make it.

If you have everything in an array already, it can be done like this:

$i = 0; //current image
$start = $_GET['start']; //number to start on
$max = 5; //number per page

foreach ($images as $img) {
    if ($start > $i) continue;
    if ($i > ($start + $max)) break;

    echo "<img src='{$img}' />";
}

Then you need to draw the page number links

for ($i = 0; $i <= (len($array) / $max); $i++) {
    echo "<a href='./thispage.php?start=" . ($i * $max) . "'>{$i}</a>";
}

Upvotes: 1

Related Questions