1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Page Navigation Problem

Discussion in 'PHP' started by EXM, May 12, 2013.

  1. #1
    Hello

    I am working on a auto index script, It can show 10 files per page from a folder. But now I am facing a problem.

    Page navigation should work like
    <<First 1 2 3 4 5 6 Last>>
    or
    <<First 1 2 3 4 5 . . . 8 9 Last>>

    But the problem it its showing all pages like i have 800 files in the folder now its showing all 1 - 80 pages.

    Some one please help me to fix this problem. Here i am pasting my present navigation code:

    <?php
        if($_GET["offset"]=="0") { echo '<a data-mini="true" data-role="button" data-inline="true" data-theme="d">First << </a>'; }
        else
        {
        echo '<a data-mini="true" data-role="button" data-inline="true" data-icon="arrow-l" data-theme="a" href="index.php?path='.$path.'&amp;offset=0">First </a>';
        echo '<a data-mini="true" data-role="button" data-inline="true" data-theme="a" href="downloads.php?view=index.php?path='.$path.'&amp;offset='.$prev.'"><< </a>';
        }
        for ($i=1; $i <= $pages; $i++) {
        $newoffset=$limit*($i-1);
        if ($newoffset != $offset) {
        ?>
        <a data-mini="true" data-role="button" data-inline="true" data-theme="a" href="index.php?path=<?php echo $path = htmlspecialchars($_GET["path"], ENT_QUOTES); $path; ?>&amp;offset=<?php print $newoffset; ?><?php print $query; ?>"> <?php print $i; ?>
        </a>
        <?php
        }   
        else {
        ?>
        <?php echo '<a data-mini="true" href="#" data-role="button" data-inline="true" data-theme="d">'.$i.'</a>';
                     
        }
        }
        if($offset==$lastnum) {
        echo '<a data-mini="true" data-role="button" data-inline="true" data-theme="d"> >>';
        echo ' Last</a>';
        }
        else
        {
        echo '<a data-mini="true" data-role="button" data-inline="true" data-theme="a" href="index.php?path='.$path.'&amp;offset='.$next.'"> >></a>';
        $lastlink = $totalnum-1;
        echo '<a data-mini="true" data-role="button" data-inline="true" data-icon="arrow-r" data-theme="a" href="index.php?path='.$path.'&amp;offset='.$lastlink.'"> Last</a></div>';
        }
        }
        }
        freddyShowNav($offset,$limit,sizeof($files),"");
        echo $page;
        echo '<br/>';
    PHP:
     
    EXM, May 12, 2013 IP
  2. dragos_tt

    dragos_tt Greenhorn

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #2
    I would suggest that you build your web application on top of some popular framework. These frameworks support by default the pagination feature, so you don't have to reinvent the wheel.

    Try http://www.truthsource.net/wp/php-pagination-class/ if you need to implement a pagination class, or you can browse the code to see how it was implemented.
     
    dragos_tt, Jun 5, 2013 IP