Solved

moving through an array of session variables...

Posted on 2000-03-13
6
126 Views
Last Modified: 2013-12-24
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
Comment
Question by:cath
6 Comments
 
LVL 1

Expert Comment

by:bigbadb
Comment Utility
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
 

Author Comment

by:cath
Comment Utility
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
 
LVL 5

Expert Comment

by:nathans
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Accepted Solution

by:
rod_nolan earned 100 total points
Comment Utility
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
 

Author Comment

by:cath
Comment Utility
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
 
LVL 1

Expert Comment

by:rod_nolan
Comment Utility
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

Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now