Skip to main content
November 19, 2007
Answered

Cfinclude calling queries

  • November 19, 2007
  • 5 replies
  • 827 views
i have 3 pages: index.cfm, user.cfm, selectgroups.cfm.

Index.cfm is the main page. it includes <cfinclude template=user.cfm>.

user.cfm includes <cfinclude template=selectgroups.cfm>.

there is a query on index.cfm that needs to be referenced by the selectgroups.cfm. how do I go about doing this. currently i get an error message indicating that queryX does not exist, but it clearly does on the index page.

thank you in advance
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    "The selectgroups.cfm page has no "knowledge" of a query run on
    index.cfm unless you save the query results to a session variable or
    something."

    The request scope is the place for this. The request scope is available
    to all elements of a page such as includes and custom tags. Save your
    query as <cfqoury name="request.myQuery"...> on the index page and then
    access it as #request.myQuery# in the selectgroups.cfm page.

    If, for some reason, it makes sense to separate these operations in your
    application.

    5 replies

    Inspiring
    November 19, 2007
    code for p1
    cfquery name="x"
    p1
    <cfdump var=#x#>
    cfinclude p2

    code for p2
    p2
    cfflush
    <cfdump var=#x#>
    cfinclude p3

    code for p3
    p3
    cfflush
    <cfdump var=#x#>

    When I run p1, I get all three dumps.
    November 19, 2007
    Thanks guys. I took the advice of paross and Ian and used a session variable (for the first time I might add). I appreciate it. Dan I could only get p3 to work if the query was on p2 not from p1. if you got it to work, i would love to see your code
    Inspiring
    November 19, 2007
    quote:

    Originally posted by: Shadyoj
    i have 3 pages: index.cfm, user.cfm, selectgroups.cfm.
    Index.cfm is the main page. it includes <cfinclude template=user.cfm>.
    user.cfm includes <cfinclude template=selectgroups.cfm>.
    there is a query on index.cfm that needs to be referenced by the selectgroups.cfm. how do I go about doing this. currently i get an error message indicating that queryX does not exist, but it clearly does on the index page.

    thank you in advance

    Despite the other two answers, it works when I do it. I wrote 3 files, p1.cfm, p2.cfm and p3.cfm. query x is on p1. p2 and p3 each have a line of text, a cfflush, and a cfdump of query x. As I said, it works.

    Your problem is not because you are using cfincludes. You have a detail wrong somewhere. I suggest starting selectgroups.cfm with a cfdump of all your variables.
    Newsgroup_UserCorrect answer
    Inspiring
    November 19, 2007
    "The selectgroups.cfm page has no "knowledge" of a query run on
    index.cfm unless you save the query results to a session variable or
    something."

    The request scope is the place for this. The request scope is available
    to all elements of a page such as includes and custom tags. Save your
    query as <cfqoury name="request.myQuery"...> on the index page and then
    access it as #request.myQuery# in the selectgroups.cfm page.

    If, for some reason, it makes sense to separate these operations in your
    application.

    Participating Frequently
    November 19, 2007
    Execute the query on the selectgroups.cfm page. The selectgroups.cfm page has no "knowledge" of a query run on index.cfm unless you save the query results to a session variable or something.

    Phil