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

Number nav for viewing records

Contributor ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

Hello;
I created a numbered navigation for cycling through DB records. When I created it, it was based on catagoryID. There were a number of catagories and this would put a navigation under the records like this:
1 | 2 | 3| more> The word Previuos would appear if you got into the records. The nav will also grow automatically if the records grew, (more we added)

Now I am changing things on this "app" I am not using catagories, but want it to just cycle through the records placing 10 records on the page at a time, and only using the ID from teh DB records to cycle through. I changed the code and it is erroring out on me now. Here is the code I am using:

<cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
<cfparam name="PageNum_GetRecord" default="1">
<cfquery NAME="tracking" datasource="#sitedatasource#" username="#siteUserID#" password="#sitePassword#">
SELECT ID, REMOTE_ADDR, HTTP_USER_AGENT, TRACK_DATE
FROM tracking
WHERE ID = #ID#
ORDER BY ID
</cfquery>

<cfparam name="startRow" default="1">
<cfparam name="maxRows" default="10">
<cfset numRows = tracking.recordCount>
<cfif startRow gt numRows><cfset startRow = Max(startRow-maxRows,10)></cfif>
<cfset endRow = Min(Evaluate(startRow + maxRows - 10),numRows)>

<body>
<cfoutput query="tracking" STARTROW="#StartRow#" maxRows="#maxRows#">
#all my output is in here#
</cfoutput>
<cfmodule
template="../CFdocs/pageNav.cfm"
totalItems="#numRows#"
numPerPage="#maxRows#"
startRow="#startRow#"
url="#cgi.script_name#?ID=#ID#&startRow=#startRow#">

My error is the following:

Variable ID is undefined.


The error occurred in C:\websites\108392zj7\admin\tracking.cfm: line 7

5 : <cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
6 : <cfparam name="PageNum_GetRecord" default="1">
7 : <cfquery NAME="tracking" datasource="#sitedatasource#" username="#siteUserID#" password="#sitePassword#">
8 : SELECT ID, REMOTE_ADDR, HTTP_USER_AGENT, TRACK_DATE
9 : FROM tracking


Can anyone help me figure out what it is I am missing and why my ID is not difined?

Thank you

Phoenix
TOPICS
Advanced techniques

Views

360

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

correct answers 1 Correct answer

Deleted User
Mar 16, 2007 Mar 16, 2007
Hi Phoenix,

I've got 1 question.

In your query

SELECT ID, REMOTE_ADDR, HTTP_USER_AGENT, TRACK_DATE
FROM tracking
WHERE ID = #ID#

Where does the #ID# come from?

You're also saying that "it is the ID in the DB that is assigned for each record".

What is actually generating the #ID#?

Is everything inside a <cfloop query="qGetID"> ... </cfloop>??

In this case it explains why you're getting an error "Variable ID is undefined" because in your code nothing is generating the #ID#

It's also a goo...

Votes

Translate

Translate
Guest
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

The problem is here: WHERE ID = #ID#

Where are you defining a value for ID? Is it a form variable? You may need to define the scope, for example form.id or url.id

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
Contributor ,
Mar 15, 2007 Mar 15, 2007

Copy link to clipboard

Copied

No this is not a form variable, it is the ID in the DB that is assigned for each record. What do I change it to to make this work. It is one page that will diplay 10 records at a time, then instead of hitting a next button, it has a numbered nav under the records breaking them down to 10 records per number. So basically it is one page doing all the work and when you click the number, I guess it would use the url id to make the records go to the next page of 10.

Phoenix

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
Mar 16, 2007 Mar 16, 2007

Copy link to clipboard

Copied

Hi Phoenix,

I've got 1 question.

In your query

SELECT ID, REMOTE_ADDR, HTTP_USER_AGENT, TRACK_DATE
FROM tracking
WHERE ID = #ID#

Where does the #ID# come from?

You're also saying that "it is the ID in the DB that is assigned for each record".

What is actually generating the #ID#?

Is everything inside a <cfloop query="qGetID"> ... </cfloop>??

In this case it explains why you're getting an error "Variable ID is undefined" because in your code nothing is generating the #ID#

It's also a good practice to specify the scope of your variables e.g. variables.ID, form.ID, url.ID, etc

I've tried a similar example with Next, Previous links and it's working fine.

Here is the code below.

Hope this helps.

Regards,
Yogesh

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
Contributor ,
Mar 16, 2007 Mar 16, 2007

Copy link to clipboard

Copied

The ID field is an auto number assigned by the DB. It is an access DB.


I will try out this code you posted, and get back on after I test it.

Phoenix

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
Contributor ,
Mar 16, 2007 Mar 16, 2007

Copy link to clipboard

Copied

LATEST
Thank you, this works without using the ID from teh DB.

Thank you.

Phoenix

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