Solved

moving through an array of session variables...

Posted on 2000-03-13
6
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:bigbadb
ID: 2612591
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
ID: 2612626
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
ID: 2613441
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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 1

Accepted Solution

by:
rod_nolan earned 100 total points
ID: 2614691
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
ID: 2620067
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
ID: 2621606
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

Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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