logo

New Response

« Return to the main article

You are replying to:

  1. I must say that I've used the dynamic number generation technique many times already in many different applications. Thank you Chris!!

    But there were some limitations that I found. Mainly if there is a huge number of pages of results the number of links would be really big. So I played around with the code and developed a way that only a certain number of links to pages are shown at one time. This functionality is much like how Altavista currently operates.

    So here's the code below to get this going so a user can navigate a view:

    REM "Define how the list should act"; numPerPage := 10; numLinks := 5;

    REM "Get the total number of items"; lookup := @DbColumn( "" : "NoCache"; ""; "ViewName"; 1 ); numDocs := @Elements( @If( @IsError( lookup ); ""; lookup ) );

    REM "Generate the number list"; numPages := @Integer( numDocs / numPerPage ); @Set( "numPages"; @If( numPages = ( numDocs / numPerPage ); numPages - 1; numPages ) ); numRange := @Explode( @TextToTime( "01/01/1900 - " + @Text( @Adjust( [01/01/1900]; 0; 0; numPages; 0; 0; 0 ); "D0S0" ) ) ); numList := ( @TextToTime( numRange ) - [01/01/1900] ) / 86400; numItems := @Elements( numList );

    REM "Generate the numbers"; startNums := @Text( numList * numPerPage + 1 ); endNums := @Text( @TextToNumber( startNums ) + numPerPage - 1 ); @Set( "endNums"; @If( numDocs < @TextToNumber( @Subset( endNums; -1 ) ); @Replace( endNums; @Subset( endNums; -1 ); @Text( numDocs ) ); endNums ) );

    REM "Get the current start and end positions"; curStartNum := @Middle( @LowerCase( Query_String_Decoded ); "&start="; "&" ); @Set( "curStartNum"; @If( curStartNum = ""; "1"; curStartNum ) ); curIndex := @Member( curStartNum; startNums ); curEndNum := @If( curIndex = 1; @Subset( endNums; 1 ); @Subset( @Subset( endNums; curIndex ); -1 ) );

    REM "Get the next and previous start numbers"; prevStartNum := @If( curIndex > 1; @Subset( @Subset( startNums; curIndex - 1 ); -1 ); "" ); nextStartNum := @If( curIndex != numItems; @Subset( @Subset( startNums; curIndex + 1 ); -1 ); "" );

    REM "Limit the number of links to be shown"; startIndex := @If( curIndex > @Round( numLinks / 2 ); curIndex - @Integer( numLinks / 2 ); 1 ) - 1; @Set( "startIndex"; @If( startIndex > ( numItems - numLinks ); numItems - numLinks; startIndex ) ); @Set( "startNums"; @Subset( @Subset( startNums; startIndex + numLinks ); -numLinks ) ); @Set( "endNums"; @Subset( @Subset( endNums; startIndex + numLinks ); -numLinks ) );

    REM "Define constants"; linkS := "<A href=\"" + URL + @If( @Contains( URL; "!OpenDocument" ); ""; "!OpenDocument" ) + "&Start="; linkM := "\">"; linkE := "</A>";

    REM "Generate the HTML "; "[ " + @If( prevStartNum = ""; ""; linkS + prevStartNum + linkM + "&lt;&lt; Prev" + linkE + " | " ) + @ReplaceSubstring( @Implode( linkS + startNums + linkM + startNums + " - " + endNums + linkE; " | " ); linkS + curStartNum + linkM + curStartNum + " - " + curEndNum + linkE; "<B>" + curStartNum + " - " + curEndNum + "</B>" ) + @If( nextStartNum = ""; ""; " | " + linkS + nextStartNum + linkM + "Next &gt;&gt;" + linkE ) + " ]"

    That's pretty much it. Best thing is you can play around with how many docs are shown on a page and how many links should be displayed at any one time by changing the numPerPage and numLinks variables respectively.

    Cheers.

    Brad

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: