• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Fixing error on "prev/next" code

Guest
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

This is the code I have to navigate through the database by previous and next links, the issue I'm having is for the previous when i click on the previous link, it stays on the same page and the issue i have with the next link is, it works fine up until there is no more information from the database to be displayed and if at that point i click on the next link the page gives an error. not sure how to fix this, can anyone help?


<CFPARAM NAME="start" DEFAULT="1">
<CFIF start + 2 GT displayinfo.RecordCount>
<CFSET maxRows = displayinfo.RecordCount - start>
<CFELSE>
<CFSET maxRows = 2>
</CFIF>

<CFOUTPUT QUERY="displayinfo" STARTROW=#start# MAXROWS=#maxRows#>
#name# <br> #address# <br><br>
</CFOUTPUT>


<cfif displayinfo.recordcount gt 2>
<CFOUTPUT>
<!--- next --->
<CFSET start = start + 2>
<CFIF start GT displayinfo.RecordCount>
<CFSET start = 1>
</CFIF>
<A HREF="/test.cfm?n=#url.n#&start=#start#"><img src="/images/next-text-arrow.gif" border="0"></A>


<!--- previous --->
<CFSET start = start - 10>
<CFIF start LE 0>
<CFSET start = (displayinfo.RecordCount \ 10) & 1>
</CFIF>
<A HREF="/test.cfm?n=#url.n#&start=#start#"><img src="/images/prev-text-arrow.gif" border="0"></A>


</CFOUTPUT>
</cfif>
TOPICS
Advanced techniques

Views

423

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 11, 2007 Apr 11, 2007

Copy link to clipboard

Copied

<!---Set your param--->

<cfparam name="StartRow" default="1">
<cfparam name="MaxRows" default="2">
<cfparam name="next" default="0">
<cfparam name="previous" default="0">

<!--- Output your query --->
<CFOUTPUT QUERY="displayinfo" STARTROW=#startRow# MAXROWS=#maxRows#>
#name# <br> #address# <br><br>
</CFOUTPUT>

<!--- set the next/previous --->
<cfset previous = startRow - MaxRows>
<cfset next = startRow + maxRows>

<!--- dispay previous the link --->
<cfif previous GT 0>
<A HREF="/test.cfm?n=#url.n#&startRow=#previous#"><img src="/images/prev-text-arrow.gif" border="0"></A>
</cfif>

<!--- display next link --->
<cfif next LTE displayinfo.recordCount>
<A HREF="/test.cfm?n=#url.n#&startRow=#next#"><img src="/images/next-text-arrow.gif" border="0"></A>
</cfif>

Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 12, 2007 Apr 12, 2007

Copy link to clipboard

Copied

Hey scarecrow, thanks for the help but there seems to be a minor issue cause im getting this message:

The value "" cannot be converted to a number

and in the url:
&startRow=#next#


I really dont know what it could be, any idea??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 12, 2007 Apr 12, 2007

Copy link to clipboard

Copied

You need to enclose the next/previous links in cfoutput

Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 15, 2007 Apr 15, 2007

Copy link to clipboard

Copied

LATEST
Here is the part of the code you asked for:

<cfset previous = startRow - MaxRows>
<cfset next = startRow + maxRows>

<cfoutput>
<!--- dispay previous the link --->
<cfif previous GT 0>
<A HREF="/test.cfm?n=#url.n#&startRow=#previous#"><img src="/images/previous-text-arrow.gif" border="0"></A>
</cfif>
</cfoutput>

<cfoutput>
<!--- display next link --->
<cfif next LTE displayinfo.recordCount>
<A HREF="/test.cfm?n=#url.n#&startRow=#next#"><img src="/images/next-text-arrow.gif" border="0"></A>
</cfif>
</cfoutput>

Thanks again for the help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation