moving through an array of session variables...

I haven't actually put fingers to keyboard to code any CF yet, I'm still just thinking about what I'd like to do. What I'd like to know is this:

say I've got 26 names, one each A-Z, and I've got a template to pull information about each person from a db and output some html to the browser. At the bottom of the template is a 'next' and 'last' button. I guess in CF-speak that when these are clicked you are effectively reloading the page and  replacing one session variable (ie the name of the record currently being pulled) with a new one (next or last, as the case may be). But how does the page know what the 'next' or 'last' session variable is? Are they held in some kind of array, and for 'next' the next record of the array is read and for 'last' the previous array entry? Or is it just the next record (ie, row) in the table that is being read from?

Like I say I'm just thinking out loud (it's a slow day in the office and I've got some points to burn...). By all means tell me to RTFM, but then you don't get the points...;-)


Who is Participating?
rod_nolanConnect With a Mentor Commented:
Hi Cath,

Here's some code that does what bigbadb was talking about, generally. It doesn't use session variables but I think it results in the same interface as what you described.

The code is specific to my query, but it's commented so you should be able to modify it to fit your needs.

Good Luck,

<!--- set the maximum number of rows to display --->
<cfset MaxRows = 1>
<!--- and set the default record to start at (if this is the first time) --->
<cfparam name="START" default="1">

<!--- Do the query to get the required details --->
<cfquery name="getContact" datasource="rodweb">
      SELECT *
      FROM Contacts
      <cfif isDefined("Form.ContactID")>
      WHERE ContactID = #Form.ContactID#
      ORDER BY LastName

<!--- output the query results --->
<cfoutput query="getContact" startrow=#start# maxrows=#MaxRows#>
      <b>#getContact.FIRSTNAME# #getContact.LASTNAME#</b><br>
      <a href="mailto:#getContact.EMAIL#">#getContact.EMAIL#</a><br>

<!--- Used to determine which row to output from the query on the next request --->
<cfset PrevStart = Start - MaxRows>
<cfset NextStart = Start + MaxRows>

<!--- only show the next or previous buttons if there are next or previous records --->
            <form action="same_page_as_this_one.cfm" method="post">
                  <input type="hidden" name="start" value="<cfoutput>#PrevStart#</cfoutput>">
                  <input type="image" src="prev.gif">
            <form action="ContactDetails.cfm" method="post">
                  <input type="hidden" name="start" value="<cfoutput>#NextStart#</cfoutput>">
                  <input type="image" src="next.gif">

well you would pull the total number of records from the datasource

<cfquery name="test" datasource="">
select * from table

then you would load a sessionvar to be set to test.recordcount.  THis would give the total records.

the next would be a count bascially the would increment where you were + 1 and the last would be test.recordcount

On the main page you would loop through the query until you found the recordnumber you were looking for

If you want code let me know but since you are just thinking I thought this would suffice
cathAuthor Commented:
oh no, I _will_ want code, I just haven't gotten around to putting it all together yet...;-)

I need to get my new machine, then get CFStudio, then set up CF Server, then I can start playing around with code... but if you'd like to give it, I'd sure like to have it...

also, any pointers to good CF tutorials that deal with this sort of thing (already have the Webmonkey CF tutorial), that would be great too.

thanks in advance.

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Check out the ColdFusion Tips Plus e-ZINE at

subscribe by sending an blank email to

I am the creator of this resource which will allow you to find code and websites to help you.
cathAuthor Commented:
many thanks for that - I look forward to playing about with the code in a few weeks when I get my new machine and get CF Studio up there.

I guess it would only be right, at this point, to disclose my source for the above code :)

The ColdFusion Web Application Construction Kit, Third Edition
Ben Forta (ISBN 0-7897-1809-x)  
p. 498 - 503

These books (the other one is called Advanced ColdFusion Application Development, ISBN 0-7897-1810-3) are essential reading if you're interested in becoming a serious ColdFusion programmer.

Good Luck,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.