1

我有一个非常复杂的脚本,它不能完全与 MySQL 一起工作,但它部分地工作。让我试着解释一下……

我的页面的结果是来自特定文件夹的纯图像名称,这意味着我使用这个函数来获取我的结果:

function get_all_images($dir)
{
    $dir = opendir($dir);
    $dirArray = array();

    while($entryName = readdir($dir)) 
    {
        if(($entryName != ".") && ($entryName != "..") && ($entryName != ".svn") && ($entryName != ".htaccess"))
        {   
            $dirArray[] = $entryName;
        }
    }

    closedir($dir);
    (sizeof($dirArray)) ? arsort($dirArray) : '';

    return (is_array($dirArray)) ? $dirArray : '';
}

这就是我基本上在我的页面中获得结果的方式:

    <?php
 include('includes/header.php');
    $images = get_all_images('i');

    $url    = str_replace('www.', '', generate_site_url());
    $flag   = false;
    $count  = 0;

    if (empty($images))
    {
        echo '<h2>There are no uploaded images</h2><br>';
    }

    foreach ($images as $image) 
    {
        $filename = $image_name = $image; 
        $image_link = $url . IMAGES_PATH . $filename;
        $user_id = fetch_user_id($image_link);

        $delete_link        = (isset($_POST['delete_link'])) ? $_POST['delete_link'] : '';
        $delete_image       = (isset($_POST['delete_image'])) ? $_POST['delete_image'] : '';

        if ($delete_admin_submit) 
        {
            unlink('./t/' . $delete_image);
            unlink('./t/big' . $delete_image);
            adminDelete('./i/' . $delete_image, $delete_link); 
            header('Location: ' . $imgit_action); 
            exit();
        }

        echo '<div class="' . ($count++ % 2 ? "odd-color" : "even-color") . '">';
            echo '<table>';
            echo '<tr><td class="fullwidth"><a class="preview_img" href="' . $image_link . '"><img src="' . $image_link . '" title="Click to enlarge" width="300" class="thumb" /></a></td></tr>';

            echo '<tr><td><span class="default">Direct link:</span>&nbsp;';
            echo '<input type="text" readonly="readonly" class="link-area" onmouseover="this.select();" value="' . $image_link . '" />';
            echo '<form method="post" action="" onsubmit="return confirmSingleDeletion();" style="display: inline;"> ';
            echo '<input type="submit" class="icon_delete" name="delete_link" value="' . $image_link . '" title="Delete this image" />';
            echo '<input type="hidden" name="delete_image" value="' . $image_name . '" />';
            echo '</form>'; 
            echo '</td></tr>';

            echo ($flag) ? '<hr /><br>' : '';

            echo '</table>';
            if (!empty($user_id))
            {
                echo '<br><strong class="normal">Uploader ID:</strong>&nbsp;';
                echo '<em class="normal">' . $user_id . '</em><br>';
            }
            echo '<br>';

        $flag = true;
    }
    ?>
    <a href="<?php echo $home_action; ?>"><span class="button-sub">&laquo; Back to Index</span></a> 
    <?php echo '</div>'; ?>
<?php include('includes/footer_alt.php'); ?>

现在我没有任何简单的线索如何开始将我的结果分成页面。我在这里处理超过 12000 个结果,加载页面需要很多时间,我需要帮助将这个大结果分解为页面。

有人愿意帮助我吗?至少给我一个线索如何开始?我将不胜感激。

非常感谢您的阅读。

4

2 回答 2

0

在收集文件名时考虑您的数组,但在对它们进行排序之后:

$imgs = array(
0 => 'image1.jpg',
1 => 'image2.jpg',
2 => 'image3.jpg',
3 => 'image4.jpg',
4 => 'image5.jpg',
5 => 'image6.jpg',
6 => 'image7.jpg',
7 => 'image8.jpg',
);
// create some vars which you can use in your pagination
$perpage = 3 ;
$page=2;
$range_end = ($perpage*$page)-1;
$range_start = ($perpage*($page-1));
$display=range($range_start,$range_end);

// loop through results
foreach($display as $show){
echo $imgs[$show];
}

这会让你开始吗?

于 2012-08-11T15:19:55.343 回答
0

感谢您尝试回答我CupsUmair Khan,但我在这里找到了可行的解决方案:

http://tiffanybbrown.com/2008/12/14/simple-pagination-for-arrays-with-php-5/

于 2012-08-11T21:18:22.560 回答