2012-08-11 18 views
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个,页面加载需要很多,我需要帮助将这个大的结果分解成页面。

任何人都愿意帮助我吗?至少给我一个线索如何开始?我会很感激。

非常感谢您的阅读。

+0

这会是任何使用你的? http://stackoverflow.com/questions/5105810/view-files-in-directory-with-pagination-php – 2012-08-11 14:30:32

+0

我会尝试从中得到一些东西。将回报。谢谢。 – Aborted 2012-08-11 14:46:13

+0

似乎无法使您的链接得到这个东西。 :\ – Aborted 2012-08-11 15:15:10

回答

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]; 
} 

这是否让你开始?

+0

请解释你是如何创建实际分页的(数字:1,2,3等,具体取决于你想要每页有多少结果以及你有多少结果) – Aborted 2012-08-11 19:37:09

+0

哦,如果有可能给我看一个与我上面提供的代码相关的示例,我不是一个伟大的编码器,对我来说事情可能会变得很复杂。 – Aborted 2012-08-11 19:55:39

相关问题