3 Replies - 2198 Views - Last Post: 06 July 2011 - 06:49 AM Rate Topic: -----

#1 irishphoenix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-May 09

coldfusion / ajax next n record problem

Posted 05 July 2011 - 10:06 AM

Hello;
I am trying to make a paging script that will allow my output to reload when you hit next or previous without reloading the page. I have it kind of working, but for some reason, my output won't show up, but the page numbers do..... Can anyone help me figure out where my problem is, I have also tried searching for a solution for this, and haven't been able to find a good working solution. I am posting my code, this little app consists of 2 pages: index.cfm and output.cfm


index.cfm:

<cflock timeout="10" type="exclusive" scope="application">
<cfquery name="getProjects" datasource="#APPLICATION.dataSource#">
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
ORDER BY Projects.Name
</cfquery>
</cflock>
<!--- calc total pages  --->
<cfset _totalperpage = 10>
<cfset _totalpages = ceiling(getProjects.recordcount/_totalperpage)>
<cfajaximport>
<!--- This control the paging ajax action --->
<script type="text/javascript">
// global var
var currentPage = 1;

// paging
function pagingbyid(pageid)
{
// navigate to index.cfm with url param pageid with the value sent to the function
ColdFusion.navigate('output.cfm?pageid='+pageid ,'ContentOutputDiv');
currentPage = pageid;
}
<cfoutput>
// next
function next()
{
if (currentPage < #_totalpages#)
{
  currentPage +=1;
  pagingbyid(currentPage);
}
// end next
}

// prev
function prev()
{
if (currentPage > 1)
{
  currentPage -=1;
  pagingbyid(currentPage);
}
//edn prev
}
</cfoutput>
</script>

<div id="ContentOutputDiv">Output will show here</div>


OUTOUT.cfm:

<cfparam name="url.pageid" default="1">

<cflock timeout="10" type="exclusive" scope="application">
<cfquery name="getProjects" datasource="#APPLICATION.dataSource#">
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
ORDER BY Projects.Name
</cfquery>
</cflock>

<cfset _totalperpage = 5>
<cfset _startrow = (url.pageid-1) * totalperpage + 1>
<cfset _endrow = _startrow + _totalperpage - 1>

<cfloop query="getProjects" startrow="#_startrow#" endrow="#_endrow#">
<cfoutput>
#PName#, more output here....
</cfoutput>
</cfloop>



Can anyone help me? this should work! The error i get is saying that total pages is not defined in the output and I only get that when I try and hit the next or previous, otherwise, there are no errors, so I'm kind of stumped, I have tried a number of variations of this with no luck so far.. maybe I'm just missing something.

This is my first time posting out here, so forgive me if I didn't give you enough info.

Is This A Good Question/Topic? 0
  • +

Replies To: coldfusion / ajax next n record problem

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: coldfusion / ajax next n record problem

Posted 05 July 2011 - 11:31 AM

Hi and welcome to DIC, irishphoenix!

Just glancing at your code (as I'm about to leave for lunch) I wanted to ask a question and make a suggestion.

Question: can you post the exact text of the error message you're getting and the line number it's supposed to be happening on? (And post the block of code containing the line number mentioned in the error)

Suggestion: can you try surrounding your Javascript code block containing the function next() in a CFOUTPUT? next() has a block where it's trying to use _totalpages in a comparison...but unless that pounded variable is within a CFOUTPUT the Javascript would throw an error.

Post back and we'll see what we can do.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 irishphoenix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-May 09

Re: coldfusion / ajax next n record problem

Posted 06 July 2011 - 06:46 AM

Hello;
I figured it out after walking away from it for a while.. I forgot to call my totalpages ... _totalpages so it was telling me it was undefined. I'm sorry to waste your time, I just made a silly mistake and missed my variable with a typo. Thank you for responding.. Next time I have a problem, I'll try this out again.
Was This Post Helpful? 0
  • +
  • -

#4 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: coldfusion / ajax next n record problem

Posted 06 July 2011 - 06:49 AM

Cool. Glad you solved your problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1