Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

moving through an array of session variables...

hi.
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...;-)

thanks,

Cath
0
cath
Asked:
cath
1 Solution
 
bigbadbCommented:
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
0
 
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.

Cath
0
 
nathansCommented:
Check out the ColdFusion Tips Plus e-ZINE at
http://www.nsnd.com/cftips

subscribe by sending an blank email to
subscribe-cftips@nsnd.com


I am the creator of this resource which will allow you to find code and websites to help you.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
rod_nolanCommented:
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,
Rod


<!--- 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#
      </cfif>
      ORDER BY LastName
</cfquery>

<!--- 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>
      #getContact.HomePhone#<br>
      #getContact.WorkPhone#<br>
      #getContact.CellPhone#<br>
</cfoutput>

<!--- 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 --->
<table><tr><td>
            <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>
</td><td>
            <form action="ContactDetails.cfm" method="post">
                  <input type="hidden" name="start" value="<cfoutput>#NextStart#</cfoutput>">
                  <input type="image" src="next.gif">
            </form>
</td></tr></table>

0
 
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.

Cath
0
 
rod_nolanCommented:
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,
Rod
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now