5 Replies Latest reply on Mar 16, 2007 1:46 PM by Irish-Phoenix

    Number nav for viewing records

    Irish-Phoenix Level 1
      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
        • 1. Re: Number nav for viewing records
          SYRRoss Level 1
          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

          • 2. Re: Number nav for viewing records
            Irish-Phoenix Level 1
            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
            • 3. Re: Number nav for viewing records
              YogeshM Level 1
              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

              • 4. Re: Number nav for viewing records
                Irish-Phoenix Level 1
                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
                • 5. Re: Number nav for viewing records
                  Irish-Phoenix Level 1
                  Thank you, this works without using the ID from teh DB.

                  Thank you.

                  Phoenix