使用数据库中的邮件模板作为标记化

时间:2015-05-17 15:31:11

标签: coldfusion

我正在使用数据库显示表中的结果,返回的数据是如下所示的数组格式:

使用以下coldfusion函数将查询结果返回到数组

<cffunction name="QueryToArray" access="public" returntype="array" output="false" hint="This turns a query into an array of structures.">
  <!--- Define arguments. --->
  <cfargument name="Data" type="query" required="yes" />
  <cfscript>    
    var LOCAL = StructNew(); // Define the local scope.
    LOCAL.Columns = data.getMetaData().getColumnLabels(); // Get the column names as an array.
    LOCAL.QueryArray = ArrayNew(1); // Create an array that will hold the query equivalent.
    for (LOCAL.RowIndex = 1 ; LOCAL.RowIndex LTE ARGUMENTS.Data.RecordCount; 
    LOCAL.RowIndex = (LOCAL.RowIndex + 1)){
        LOCAL.Row = StructNew();
        for (LOCAL.ColumnIndex = 1 ; LOCAL.ColumnIndex LTE ArrayLen(LOCAL.Columns); 
        LOCAL.ColumnIndex = (LOCAL.ColumnIndex + 1)){
            LOCAL.ColumnName = LOCAL.Columns[LOCAL.ColumnIndex];
            LOCAL.Row[LOCAL.ColumnName] = ARGUMENTS.Data[LOCAL.ColumnName][LOCAL.RowIndex];
        }
        ArrayAppend(LOCAL.QueryArray, LOCAL.Row);
    }
    return(LOCAL.QueryArray);
    </cfscript>
</cffunction>

我的表格数据是这样的

id       name          description
1        ice           hello {name}, how are you!
2        fix           hello {name}, how are you!
3        cnt           hello {name}, how are you!
4        ice           hello {name}, how are you!
5        ice           hello {name}, how are you!

所以我想循环遍历数组以将相关记录放入textarea然后将它们全部更新为一体,我应该怎么做,请指导谢谢

0 个答案:

没有答案