1

I have a pretty complicated script that doesn't fully work with MySQL, it does partially though. Let me try to explain...

The results of my page are purely image names from a specific folder, means I use this function to get my results:

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 : '';
}

This is how I basically get results in my page:

    <?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'); ?>

Now I have not ANY simple clue how to start breaking my results into pages. I'm working here with over 12000 results and it takes a lot for the page to load, I need help to break this big result into pages.

Anyone willing to help me? At least give me a clue how to start? I would be really grateful.

Thanks a lot for reading.

Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94
aborted
  • 4,481
  • 14
  • 69
  • 132

2 Answers2

0

Consider your array as you collect up the file names but after you have sorted them:

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

Does that get you a start?

Cups
  • 6,901
  • 3
  • 26
  • 30
  • please explain how you create the actual pagination too (the numbers: 1, 2, 3 etc. depending on how many results you want per page and how many results you have) – aborted Aug 11 '12 at 19:37
  • Oh and if it's possible to show me a an example connected with my code provided above, I'm not much of a great coder, thing might get complicated for me easily. – aborted Aug 11 '12 at 19:55
  • Please help on the issue. https://magento.stackexchange.com/questions/316910/magento-2-custom-added-ajax-pagination-not-working – Kirti Nariya Jul 10 '20 at 04:15
0

Thanks for trying to answer me Cups and Umair Khan, but I found the working solution here:

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

aborted
  • 4,481
  • 14
  • 69
  • 132
  • Please help on the issue. https://magento.stackexchange.com/questions/316910/magento-2-custom-added-ajax-pagination-not-working – Kirti Nariya Jul 10 '20 at 04:16