这个图像编辑器在php foreach循环上的分页

时间:2013-07-02 18:54:06

标签: php foreach pagination

帮助foreach分页php 我有这个代码:

/*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

例如,红色框是我的想象(我添加了油漆) 无论谁能帮助我

谢谢

1 个答案:

答案 0 :(得分:1)

通常在分页时,您需要使用$ _GET来确定要在特定页面上显示的内容。它可以是简单或复杂的,你想做它。

如果你已经拥有数组中的所有内容,可以这样做:

$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}' />";
}

然后你需要绘制页码链接

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