0

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

例如,红色框是我想象的(我用油漆添加的)谁可以帮助我

谢谢你

4

1 回答 1

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>";
}
于 2013-07-02T19:10:07.930 回答