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.

New Topic/Question
Reply




MultiQuote




|