ColdFusion: need to loop through query and set session vars for output

Posted on 2011-10-05
Last Modified: 2012-06-21
currently capturing session vars for Application Admin user roles this way:
<CFIF #qry_findAppAdmin.recordCount# GT 0>
      <cfset session.AppAdminFName = #qry_findAppAdmin.first_name#>
      <cfset session.AppAdminLName = #qry_findAppAdmin.last_name#>
      <cfset session.AppAdminEmail = #qry_findAppAdmin.email_address#>
      <cfset session.AppAdminPhone = #qry_findAppAdmin.user_phone#>
      <cfset session.AppAdminFName = ''>
      <cfset session.AppAdminLName = ''>
      <cfset session.AppAdminEmail = ''>
      <cfset session.AppAdminPhone = ''>

Now must handle multiple Application Admin users, not just one. Am hung up on how to code an array or such to create multiple session variables. Immediate goal: need to send multiple emails (i..e. cfmail ) to multiple Application Administrators.

Thanks very much
Question by:mchristopher
    LVL 39

    Expert Comment


    The primary use of session variables is to maintain a login and other session-specific information.   It sounds like you should not use session variables for the purpose you've described.  The email addresses do not all belong to the person logged in, so don't asscociate them with his session.

    To do what you want, simpley query the admin and loop through them using CFMAIL to email each one..

    Author Comment

    Understood. Just following (somewhat blindly) the template at hand.
    Will try the loop and let you know.
    LVL 39

    Accepted Solution

    Did that work?

    Author Closing Comment

    I already solved the issue by looping through the query and converting the results into an array. I found the code to do this on Google, not through the answer posted. The answer told me what to do not how to do it.
    Partial credit is my recommendation. Thanks.
    LVL 39

    Expert Comment

    That's no problem.

    For future reference however, if you are going to grade below an "A" grade you need to ask for additional information first.   Your last post was that you would give it a try and let me know.  

    Regarding the question, I don't know the specifics of your code (perhaps there is some unusual circumstance) but from what you posted, I stand by the answer... there's no need for you to create session variables or an array.  If you're just pulling the admins from the database, then simply loop through your query and send them each an email...

    If you feel you need to do session variables or arrays or something, then the question does not supply enough information to justify it these extra steps.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math ( While this method is not o…
    Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    732 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

    21 Experts available now in Live!

    Get 1:1 Help Now