SELECT ARTICLE FROM TEST1 WHERE ID=#URL.ID#
#mid(qArticle.article,val(maxChars*(url.page-1)+1),maxChars)#
Page #i# 
[allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => externalError [ip] => ighidan@yahoo.c [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Pagination with CF - Coldfusion - Advanced Techniques

Pagination with CF - Coldfusion - Advanced Techniques

Hi, I am creating an online magazine. So whenever I call an article out from my MS Access Database, it will display about 1000 characters of text. How do I make ColdFusion separate these text into 4 pages of 250 characters each? Can someone point me to a sample code? Thanks!...

  1. #1

    Default Pagination with CF

    Hi, I am creating an online magazine. So whenever I call an article out from my
    MS Access Database, it will display about 1000 characters of text. How do I
    make ColdFusion separate these text into 4 pages of 250 characters each? Can
    someone point me to a sample code? Thanks!

    Daniel Eng Guest

  2. #2

    Default Re: Pagination with CF

    Hi Daniel,

    Check the attached code, it will need some enhancements such as caching the
    query for better performance :) Anyway, create a table "test1" with the fields
    "ID" and "Article" where the ID field is autonumber and the Article field is
    memo. You will also need to setup a DSN called "test" and name this page
    "test1.cfm" ... Goodluck and code is below:


    --------------------------------------------------------------------------------
    ----------------
    <!--- I suppose that this page is named test1.cfm --->
    <!--- Set default parameters --->
    <cfparam name="url.id" default="1">
    <cfparam name="url.page" default="1">
    <cfset maxChars=250>

    <!--- A query to retrieve an article --->
    <cfquery datasource="test" name="qArticle" maxrows="1">
    SELECT ARTICLE FROM TEST1 WHERE ID=#URL.ID#
    </cfquery>

    <!--- Display page according to URL.page --->
    <div style="background:EDEDED">

    <cfoutput>#mid(qArticle.article,val(maxChars*(url. page-1)+1),maxChars)#</cfoutpu
    t>
    </div>
    <!--- Display clickable page numbers according to maxChars --->
    <div>
    <cfloop from="1" to="#val(len(qArticle.article)\maxChars)#" index="i">
    <cfoutput>
    <a href="test1.cfm?page=#i#&id=#url.id#">Page #i#</a>&nbsp;
    </cfoutput>
    </cfloop>
    </div>

    externalError Guest

  3. #3

    Default Re: Pagination with CF

    Hey thanks! I haven't got down to trying this code yet but it certainly do look promising! Will feedback once I try it out. :)
    Daniel Eng Guest

  4. #4

    Default Re: Pagination with CF

    Hey, thanks it works just like I wanted it to...

    There's this one thing though... can I calculate it by words or sentences
    instead of character? It looks really quite funny with the pages separated in
    the middle of a word? Possible? Please help! :)

    Daniel Eng Guest

  5. #5

    Default Re: Pagination with CF

    One way to do this is to extract the maximum number of characters you want to
    display, then search backwards from the end of the string to find a word
    delimiter such as a space, comma, period, etc. This snippet takes the first 250
    characters and reverses them. It then searches for the first delimiter,
    extracts the text from that point on, and reverses it back to normal order.

    You'd also want to get the length of the final string to use as your starting
    point for the next page.

    -Paul



    <CFSCRIPT>
    temptext = Reverse(Left(qarticle.article,250));
    showtext = Reverse(Mid(temptext,FindOneOf(". ?!",temptext),250));
    </CFSCRIPT>

    dempster Guest

  6. #6

    Default Re: Pagination with CF

    hey guys, i've been trying to get the script to pass the correct length to each
    specific page but i can't seem to get it right... here's my code:


    THIS PAGE: test.cfm
    <cfparam name="url.PAGE" default="1">
    <cfparam name="url.art_ID" default="">
    <cfparam name="url.minChars" default="0">
    <cfset maxChars=1500>
    <cfset minChars=#url.minChars#>
    <cfset nexChars=minChars + maxChars>

    <cfquery name="getArticle" datasource="coredb" dbtype="odbc">
    SELECT article.*
    FROM article
    WHERE article.art_ID=#url.art_ID#
    </cfquery>

    <CFSCRIPT>
    countext = Reverse(Left(getArticle.art_content,nexChars));
    showtext = Reverse(Mid(countext,FindOneOf(">",countext),maxCh ars));
    </CFSCRIPT>


    <cfoutput>#mid(showtext, val(maxChars*(URL.page-1)+1),maxChars)#</cfoutput>

    <cfloop from="1" to="#maxPage#" index="i">
    <cfoutput><a href="test.cfm?page=#i#&minChars=#totaltext#">#i#</a></cfoutput>
    </cfloop>

    Daniel Eng Guest

  7. #7

    Default Re: Pagination with CF

    The parameter you need to pass from one page to the next is the start
    character. For example, if the first page finds a space at character 239, the
    second page begins at character 240. It doesn't really matter what the page
    number is, unless you want to show that. The code below should work but it
    probably needs a little more work (checking for the last page, for example).

    -Paul



    <CFSET maxchars = 250>
    <CFPARAM NAME="URL.startchar" DEFAULT="1">
    <CFQUERY NAME="getArticle" DATASOURCE="coredb">
    SELECT article FROM cnExtraArticles WHERE ArticleID = #URL.art_ID#
    </CFQUERY>
    <CFSCRIPT>
    temptext = Reverse(Mid(getArticle.article,URL.startchar,maxch ars));
    showtext = Reverse(Mid(temptext,FindOneOf('. ?!"',temptext),maxchars));
    newstart = Len(showtext) + URL.startchar;
    </CFSCRIPT>
    <CFOUTPUT>#showtext#<BR>
    <BR>
    <A HREF="pages.cfm?art_ID=#URL.art_ID#&startchar=#new start#">Next Page</A>
    </CFOUTPUT>

    dempster Guest

  8. #8

    Default Re: Pagination with CF

    Hey thanks Paul. It definitely would work for now...

    by the way, for the funtion FindOneOf can I get it to find one set of
    characters (eg: "</p>") instead of "<", "/", "p", ">" individually? Thanks!

    Daniel Eng Guest

  9. #9

    Default Re: Pagination with CF

    Use the Find or FindNoCase function to locate a substring in a string:

    Find("</P>", article)

    It returns the position of the substring.

    -Paul
    dempster Guest

Similar Threads

  1. Book Pagination (.indb) Continuous Pagination (HELP!)
    By David_G_Wolf@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 12
    Last Post: September 21st, 01:14 PM
  2. Pagination
    By Emilie_Giguere@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 1
    Last Post: September 20th, 07:45 PM
  3. Pagination help?
    By Renee_Tanner@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 5
    Last Post: July 17th, 01:26 PM
  4. Pagination?
    By Thomas_001 in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: August 18th, 04:39 PM
  5. Pagination issue
    By AlamoMelt in forum Dreamweaver AppDev
    Replies: 2
    Last Post: February 18th, 08:20 PM

Bookmarks

Posting Permissions

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