Pages

Monday, March 17, 2014

How to Display "Next" and "Previous" in ColdFusion

ColdFusion is a scripting language that helps Web developers write dynamic, data-driven Web pages quickly. The ColdFusion language helps developers by providing an abundance of built-in functions to view, manage and display data. ColdFusion's approach to providing pagination for database-driven Web pages allows developers to determine the current page, list data and display links to pages that precede or follow the current page of data.

Instructions

    1

    Determine how many records will be shown on each page, and create a variable to hold that number. For example, if you wish to show 10 records per page, you might create a variable called "records_on_page" and set it to 10:

    2

    Find out how many records the database holds, and store that number in a variable. For example, if the database included an column called id for each record in the table names_of_pages:

    SELECT COUNT(id) AS records FROM names_of_pages

    3

    Number the pages in your database-driven report based on data derived from your database, and determine the first record to be displayed based on the current page number. The first line of the following sample code demonstrates how to set the variable name that refers to the current page to 1, so that displays start with the first page of data. The second line of sample code demonstrates how to determine which record should be displayed first on the current page.

    4

    Set the "Previous Page" link by first determining if a previous page exists, and if so, creating a link to it. To continue the previous examples, this sample code first checks to see if the current page is number 1; if so, it outputs plain text that informs the user that no previous page exists. If the current page isn't the first page, it outputs text that is linked to the previous page.

    No Previous Page

    Previous Page

    5

    Set the "Next Page" link by first determining if the current page is the last page, and if not, creating a link to the following page. This sample code first determines how many records have already been displayed by multiplying the current page number by the number of records on each page, and determining if the result is less than the total number of records in the database. If so, it outputs text that is linked to the next page. If all records have been displayed, it outputs plain text that informs the user that no more pages are available.

    Next Page

    No Next Page

0 comments:

Post a Comment