Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Advance Dynamic Paging

    Greetings all,

    I have been using a simple dynamic paging script to print out the pages for my application. it works fine until I have over 15 pages to scroll and cannot fit them nicely in a line. I saw on certain websites, they have page navigation like:

    prev < 2 ... 10 > next

    I was wondering how I can amend my code to do that?

    The code I have is as follows:-

    PHP Code:

    $result 
    mysql_query($sql);
    $rows_per_page=15;
    $total_records=mysql_num_rows($result);
    $pages ceil($total_records $rows_per_page);
                
    echo 
    "<p>$total_records records in database.</p>";
    if (!isset(
    $screen))
    $screen=0;
    $start $screen $rows_per_page;
    $sql .= "LIMIT $start, $rows_per_page";
    $result mysql_query($sql);

    while(
    $myrow=mysql_fetch_array($result))
    {
    extract($myrow);
    // print out data here.
    }
    // create the dynamic links
        
    if ($screen 0)    {
            
    $j $screen 1;
            
    $url "$PHP_SELF?action=list&type=$design_id&screen=$j";
            echo 
    "<a href=\"$url\">Prev</a>";
        }

        
    // page numbering links now

        
    for ($i 0$i $pages$i++)    {
            
    $url "$PHP_SELF?action=list&type=$design_id&screen=" $i;
            
    $j $i 1;
            echo 
    " | <a href=\"$url\">$j</a> | ";
        }

        if (
    $screen $pages-1)    {
            
    $j $screen 1;
            
    $url "$PHP_SELF?action=list&type=$design_id&screen=$j";
            echo 
    "<a href=\"$url\">Next</a>";
        } 
    The above code display my pages like:-
    1 | 2 | 3 | 4 | next etc,

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Change :
    PHP Code:
    for_($i 0;_$i_<_$pages;_$i++)____{

    ________$url_=_"$PHP_SELF?action=list&type=$design_id&screen="_._$i;

    ________$j_=_$i_+_1;

    ________echo_"_| <a_href=\"$url\">$j</a> |_";

    ____
    into
    PHP Code:
    for_($i_=_0;_$i_<=_10;_$i++)____{

    ________$url_=_"$PHP_SELF?action=list&type=$design_id&screen="_._$i;

    ________$j_=_$i_+_1

    ________echo_"_| <a_href=\"$url\">$j</a> |_";

    ____}
    If (
    $pages 10) {
            
    $url_=_"$PHP_SELF?action=list&type=$design_id&screen=11";

    ________echo_"_| <a_href=\"$url\">$j</a> |_";
    echo

    well, it'll need some extra's bcause i can imagen you would like to get the next 10 links (previous - 11-20 - next) so you'll have a few extra conditions like
    PHP Code:
    if ($screen 10) {
        echo 
    previous .....

    and you then can't set the screen to $i but you need to have another incrementing variable inside the for-loop like
    PHP Code:
    $lowest 10;
    for_($i_=_0;_$i_<=_10;_$i++)____{

    _______ $url_=_"$PHP_SELF?action=list&type=$design_id&screen="_._$lowest;

    ________$lowest ++; 
            
    $j_=_$i_+_1;
    ________echo_"_| <a_href=\"$url\">$j</a> |_";

    ____
    end so on

    <edit>ignore the underscores, i don't know how they get added)</edit>

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    112
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    thank you. raf.. I'll give it a shot later.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •