Results 1 to 8 of 8

Thread: How to create Back / Next Links - Resolved

  1. #1

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Resolved How to create Back / Next Links - Resolved

    Hi,

    I have a big set of records and i want to have Back / Next thing in there with page numbers for example:

    If i am on page 10 then it should show up like:

    Back 7 8 9 (10 disabled) 11 12 13 Next

    How can i do this please help very urgent.

    Thanks
    Last edited by AvisSoft; Apr 27th, 2005 at 04:17 AM. Reason: Marking it as resolved.
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to create Back / Next Links

    Its referred to as link pagination and there is a thread about it here which has a useful function to generate the links.
    Last edited by visualAd; Apr 21st, 2005 at 06:31 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Re: How to create Back / Next Links

    Hi,

    Uhm...sorry but it took me to a visual basic source page which has something discussing about loops. I need to do this in PHP with MySQL records.

    Thanks
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to create Back / Next Links

    Sorry - I'm not sure how i managed that - but I've corrected the link now.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Question Re: How to create Back / Next Links

    Hi,

    Thanks for the link, i think this is just what i needed but i am still not sure how to use that function ..please tell me how can i use it ?

    Thanks
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to create Back / Next Links

    The function there deals with generation of the links. You will need to supply it with the following information to generate the HTML links.
    • Total items altogether.
    • Items to display per page.
    • The current page.
    • The link used to generate the page.

    I have written a small script which demonstrates how to use the function in conjunction with a database. You can see the example script here:

    http://adam.codedv.com/examples/pagination.php

    This is the page source code:
    PHP Code:
    <?php
        mysql_connect
    ('host''username''password');
        
        
    /* get the total items to display per page */  
        
    if (!isset($_GET['pp'])) {
            
    $pp 10;
        } else {
            
    $pp intval($_GET['pp']);
        }

        
    /* get the page number to display */
        
    if (!isset($_GET['p'])) {
            
    $p 1;
        } else {
            
    $p intval($_GET['p']);
        }

        
    /* find the start record */
        
    $start = ($p $pp) - $pp;

        
    /* build the query */
        
    $query "SELECT SQL_CALC_FOUND_ROWS txt FROM items LIMIT $start,$pp";

        if (! 
    $result mysql_query($query)) {
            echo(
    $db->error());
            die(
    'Query error.');
        }

        
    /* find the total number of records */
        
    $query 'SELECT FOUND_ROWS()';

        if (! 
    $found mysql_query($query)) {
            echo(
    $db->error());
            die(
    'Query error.');
        }
        
        
    $row mysql_fetch_row($found);
        
    $total_rows $row[0];
    ?>
    <html>
        <head>
            <title>Pagination Example</title>
        </head>
        <body>
            <table>
                <?php while ($row mysql_fetch_row($result)): // print all the rows ?>
                <tr>
                    <td><?php echo($row[0]); ?></td>
                </tr>
                <?php endwhile; ?>
            </table>
        <p><?php echo(createlinks($total_rows$pp$p$_SERVER['PHP_SELF'] . "?pp=$pp&p=")) // print out the links ?></p>
        </body>
    </html>
    <?php
        
    function createlinks($totalItems$perPage$currentPage$link) {
            
    // First, figure out the number of pages there will be total:
            
    $totalPages floor($totalItems $perPage);
            
    $totalPages += ($totalItems $perPage != 0) ? 0;

            
    // Start building page links:
            
    if ($totalPages 1) {
                
    $output 'Pages [' $totalPages '] ';
        
            
    $loopStart 1$loopEnd $totalPages;
            
            if (
    $totalPages 5) {
                if (
    $currentPage <= 3) {
                    
    $loopStart 1;
                    
    $loopEnd 5;
                } else if (
    $currentPage >= $totalPages 2) {
                    
    $loopStart $totalPages 4;
                    
    $loopEnd $totalPages;
                } else {
                    
    $loopStart $currentPage 2;
                    
    $loopEnd $currentPage 2;
                }
            }

                
    // Add the "first page" link:
                
    if ($loopStart != 1) {
                    
    $output .= '<a href="' $link '1">«</a> ';
                }

                
    // Use the variables we setup above to loop the links:
                
    for ($i $loopStart$i <= $loopEnd$i++) {
                    
    // If this is our current page:
                    
    if ($i == $currentPage) {
                        
    // Output bold without a link:
                        
    $output .= '<b>' $i '</b> ';
                    
    // This is not our current page:
                    
    } else {
                        
    // Output the link:
                        
    $output .= '<a href="' $link $i '">' $i '</a> ';
                    }
                }

                
    // Add the "last page" link:
                
    if ($loopEnd != $totalPages) {
                    
    $output .= '<a href="' $link $totalPages .'">»</a> ';
                }

                return 
    $output;
            } else {
                return 
    '';
            }
        }        
    ?>
    Last edited by visualAd; Oct 5th, 2005 at 12:54 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How to create Back / Next Links

    Has your problem been solved? - If so then please mark this thread as resolved.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459

    Re: How to create Back / Next Links

    Hi,

    Thanks for the help but the code you provided did'nt helped..so i had to use old code with some modifications.

    Thanks
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

Posting Permissions

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



Click Here to Expand Forum to Full Width