Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I am trying to Output query through form variables .....

New Here ,
Dec 16, 2009 Dec 16, 2009


<cfquery name="cr" datasource="#session.db#" maxrows="10">
SELECT #form.collist# FROM #session.tn#
</cfquery>
<cfoutput>
<strong>SELECT</strong> #form.collist# <strong>FROM</strong> #session.tn#
</cfoutput>

<cfdump var="#cr#">

<cfset strList=#collist#>
<cfloop index="index" list="#strList#" delimiters="#chr(13)##chr(11)#">
<cfset total = ListLen(strList)>
</cfloop>


<table align="center" border="1">
<tr>
<cfloop index="z" from="1" to="#total#">
<td><cfoutput>#trim(listGetAt('#index#',Z,','))#</cfoutput></td>
</cfloop>
</tr>
<cfoutput query = "cr">
<tr>
<td>what shoud I use your to display query</td>
</tr>
</cfoutput>
</table>

502
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Dec 16, 2009 Dec 16, 2009

Here is a quick sample that might help you.

<cfset colList="name,email" />
<cfset tableName="users" />

<cfquery name="report" datasource="mydsn">
     SELECT #colList# FROM #tableName#
</cfquery>

<html>

<head>
     <title>Report</title>
</head>

<body>

<table border="1" cellpadding="2">

     <thead>
          <tr>
          <cfoutput><cfloop list="#colList#" index="colItem"><th>#HtmlEditFormat(colItem)#</th></cfloop></cfoutput>
          </tr>
     </thead>

     <tbody>
     <cfoutput query="report">
          <tr>

...
Translate
LEGEND ,
Dec 16, 2009 Dec 16, 2009

You may find some hints in this thread.

http://forums.adobe.com/thread/539697?tstart=0

If you need more help after you read it, by all means, ask.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 16, 2009 Dec 16, 2009

Can you clarify your question?  I'm not exactly sure what you're trying to accomplish.  Can you provide a sample query and a sample of the desired results as well as any error messages you are receiving.

You should be careful when using variables inside a SQL statement.  This could result in data tampering.  For example a user could submit a form field containing or named ";DELETE FROM users;" resulting in a query that removes data.  You should use a white list of acceptable column/table names if you need to support user created queries.

More information on SQL injection
http://en.wikipedia.org/wiki/Sql_injection

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 16, 2009 Dec 16, 2009

what I am trying to do is to create report generation form

1) first form user select DAtbase, tabel and column names (#form.colllist#)

then i n action page I had hrdcored this variables into cfquery to pull records

It works fine if dump but I am unable to display in table format because all columns that user selected

are in a single form variable

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 16, 2009 Dec 16, 2009

Here is a quick sample that might help you.

<cfset colList="name,email" />
<cfset tableName="users" />

<cfquery name="report" datasource="mydsn">
     SELECT #colList# FROM #tableName#
</cfquery>

<html>

<head>
     <title>Report</title>
</head>

<body>

<table border="1" cellpadding="2">

     <thead>
          <tr>
          <cfoutput><cfloop list="#colList#" index="colItem"><th>#HtmlEditFormat(colItem)#</th></cfloop></cfoutput>
          </tr>
     </thead>

     <tbody>
     <cfoutput query="report">
          <tr>
               <cfloop list="#colList#" index="colItem">
                    <td>#HtmlEditFormat(report[colItem][report.currentRow])#</td> <!--- use array notation to access column in query object syntax is query["COLUMN_NAME"][ROW_NUMBER] --->
               </cfloop>
          </tr>

     </cfoutput>

     </tbody>


</table>

</body>
</html>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 16, 2009 Dec 16, 2009
LATEST

thanks, I did find out work around using evaluate function

but your code simple and best I will use it

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources