0 Replies Latest reply on Mar 5, 2009 6:55 AM by CFmonger

    problems with an advance next n record link

    CFmonger Level 1
      I have 2 pages that work together, 1 of the pages has 3 jobs it processes. You can go to this page by 2 ways. You can click on a link that shows all the projects in the table, and if you go to the page by selecting the category it is linked to, it only brings up the projects in that category.

      Right now this code works when you go to the page to view all the projects. When you come to the page to just view all the projects in the selected category, it works, but when you click either the page number or the next button, it brings all the projects back and not just the ones for that category.

      How do I make this next / prev button smart enough to know the difference? Also, there is a numbered nav, is it possible to make that do the same?

      This is my code:

      Link to get to the projects page by category:
      <a href="project-manager.cfm?CategoryID=#CategoryID#" class="nav">Edit Projects</a>

      Link to look at all the projects:
      <a href="project-manager.cfm">view all projects</a>

      The query and next / prev code:

      <cflock timeout="10" type="exclusive" scope="application">
      <cfquery name="getProjects" datasource="creative">
      SELECT Projects.Name AS PName, Projects.ProjectID AS ID,
      Categories.Name AS CName, Categories.CategoryID
      FROM Projects INNER JOIN Categories ON projects.CategoryID = Categories.CategoryID
      <cfif StructKeyExists(url, 'ID')>
      WHERE Categories.CategoryID = <cfqueryparam CFSQLType="CF_SQL_INTEGER" value="#URL.ID#" />
      ORDER BY Projects.Name
      ORDER BY Categories.Name
      <cfset rowsPerPage = 6>
      <cfparam name="URL.startRow" default="1" type="numeric">
      <cfset totalRows = getProjects.recordCount>
      <cfset endRow = min(URL.startRow + rowsPerPage - 1, totalRows)>
      <cfset startRowNext = endRow + 1>
      <cfset startRowBack = URL.startRow - rowsPerPage>

      Displaying <b>#URL.startRow#</b> to <b>#endRow#</b> of <b>#totalRows#</b> Records

      <cfif startRowBack GT 0><a href="#CGI.script_name#?startRow=#startRowBack#" class="nav">Previous Records</a></cfif>

      <cfif startRowNext lte totalRows><a href="#CGI.script_name#?startRow=#startRowNext#" class="nav">Next Records</a></cfif>

      <!--- this is the numbered nav, 1 | 2 | 3... --->
      <cfset thisPage = 1>
      <cfloop from="1" to="#totalRows#" step="#rowsPerPage#" index="pageRow">
      <cfset isCurrentPage = (pageRow gte URL.startRow) and (pageRow lte endRow)>
      <cfif isCurrentPage>
      <a href="#CGI.script_name#?startRow=#pageRow#" class="nav">#thisPage#</a></cfoutput></cfif>
      <cfset thisPage = thisPage + 1>

      <cfloop query="getProjects" startRow="#URL.startRow#" endrow="#endRow#"><cfset class = iif(getProjects.currentRow mod 2 eq 0, " 'DataA' ", " 'DataB' ")>
      <form name="myform" action="Action.cfm" method="post">
      <input type="hidden" name="ID" value="#ID#">
      <input type="submit" name="proj_Edit" value=" Edit ">
      <input type="submit" name="proj_Delete" value="Delete">

      Right now it works to some degree. I can't get the next n buttons to tell the difference between just category next or all project next. Can anyone help me?