<cfoutput> within a <cfoutput> from a db

Discussion in 'Programming' started by chosenlight, Oct 21, 2008.

  1. #1
    i have the following problem, hoping someone can help me out with it.

    In the file :

    <cfquery name = "One" datasource = "sss">
    Select X
    From TheTable
    </cfquery>

    <cfquery name = "Two" datasource = "sss">
    Select FileName (for example)
    From TheTable
    where Y = inputed from form
    </cfquery>


    <cfouput query = "One">
    #X#
    </cfoutput>

    End of File

    X Cell in the Data Base :

    <cfoutput query = "two" datasource = "sss">
    #FileName#
    </cfoutput>

    The result of this outputs "#FileName#" and not the content in the filename cell. I tried the code out side the database and outside the outter cfouput tag and it works fine.

    Any help would greatly be appreciated...
    thanks in advance
     
    chosenlight, Oct 21, 2008 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't quite understand the question. Let's say TheTable contains one row of data and two columns:

    TableName: TheTable
    Row, X, Filename
    ---------------
    1, 'abc', 'myDocument.doc'


    The code you posted would output "abc" for query one and "myDocument.doc" for query two.
     
    cfStarlight, Oct 22, 2008 IP
  3. robhustle

    robhustle Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    He wants to store code in the DB and execute it dynamically. Why he wants to do that is another question.

    Evaluate doesn't really work here... it gets ugly.

    If he were only storing query loops, he could just store the values, like you mention. But, that wont work if he just wants to store and execute arbitrary code.

    What he could do is write the code to disk first, then include it. But, that would be a monster of inefficiency.

    If I were dealing with code and needed to store it in the DB, I would create objects and serialize them with something like WDDX. THEN store them. When I needed them, I would just retrieve them, deserialize them and use them as is.

    But based on the tech level of the original question, I don't really feel like explaining that process.
     
    robhustle, Oct 22, 2008 IP
  4. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, I was afraid you were going to say that. As I have ever done anything along those lines, I am not even remotely qualified to answer this one ;-)
     
    cfStarlight, Oct 22, 2008 IP
  5. robhustle

    robhustle Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    If you DO want to go the serialization, try these functions:

    <cffunction name="serializeCFC" access="public" output="false" returntype="String">
    <cfargument name="cfc" type="component" required="true">

    <cfset var byteOut = CreateObject("java", "java.io.ByteArrayOutputStream") />
    <cfset var objOut = CreateObject("java", "java.i:confused:bjectOutputStream") />

    <cfset byteOut.init() />
    <cfset objOut.init(byteOut) />
    <cfset objOut.writeObject(arguments.cfc) />
    <cfset objOut.close() />

    <cfreturn ToBase64(byteOut.toByteArray()) />
    </cffunction>

    <cffunction name="deserializeCFC" access="public" output="false" returntype="any">
    <cfargument name="base64cfc" type="string" required="true" />

    <cfset var inputStream = CreateObject("java", "java.io.ByteArrayInputStream") />
    <cfset var objIn = CreateObject("java", "java.i:confused:bjectInputStream") />
    <cfset var com = "" />

    <cfset inputStream.init(toBinary(arguments.base64cfc)) />
    <cfset objIn.init(inputStream) />
    <cfset com = objIn.readObject() />
    <cfset objIn.close()>

    <cfreturn com />
    </cffunction>

    Source:

    http://remotesynthesis.com/post.cfm/serialize-and-deserialize-a-component-in-coldfusion-8
     
    robhustle, Oct 22, 2008 IP
  6. chosenlight

    chosenlight Active Member

    Messages:
    363
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Thanks for getting back and posting, ill try the above.....

    Your right, i am not much of a programmer....but i get by; what i don't know, i research and learn to do...saves me money!

    The reason why i want to store code in db is i have a larger site (100+ pages) that i am about to expand to 1000+ pages. So i built a template that gets all the content from a db (instead of having a 1000+ static pages). Where the problem lies is that about 3 dozen pages or so will require me to run another query. N E way thats my problem...thanks for the above advice, if i cant figure it out ill improvise. Originally i thought that it'd be no problem to store code, but i guess i was wrong....could i at least store a <cfinclude> function or that won't work either???
     
    chosenlight, Oct 22, 2008 IP
  7. robhustle

    robhustle Peon

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yeah, try cfinclude, that sounds like it would work better
     
    robhustle, Oct 22, 2008 IP