我有2张桌子.一个是类别,第二个是问题.
category table:
category_id
category_name
questions table:
question_name
question_id
category_id
Run Code Online (Sandbox Code Playgroud)
如何循环显示所有类别名称并显示在每个类别名称下分组的问题?使用ColdFusion,所以我假设我应该使用<CFLOOP>
结果看起来应该是这样的.
组别
产品组别
我有cfquery循环,然后我已经将一个查询列值(Text)显示为锚标记.
例如
<cfloop query="testQuery">
<a href="##">#testQuery.Title#</a>
</cfloop>
Run Code Online (Sandbox Code Playgroud)
假设testQuery.Title变量返回"定义字符的解释/发音(用于东亚排版)"但我需要打破句子的例子
"定义
字符的解释/发音(东亚排版)"
我被困了......不记得如何使这项工作.代码:
<cfquery name = "getsomething>
select a, b, c
from d
where id = '1'
</cfquery>
<cfloop collection="#arguments#" item="argument">
<cfif #StructFind(arguments, argument)# neq #getsomething.argument[0]#><!--- here's the problem --->
do something
</cfif>
</cfloop>
Run Code Online (Sandbox Code Playgroud)
查询返回一条记录; 我需要获取该记录的每列的值.列名是变量(参数).我需要替换什么语法
#getsomething.argument[0]#
Run Code Online (Sandbox Code Playgroud)
?谢谢.
我试图使用cfloop循环形式0.0到5.0,但它取出小数点,并从0到5循环.
这是我的代码
<select name="cweight">
<option value="">---</option>
<cfloop index = "cweight" from = "0.0" to = "5.0">
<option value="#cweightid#">#cweight#</option>
</cfloop>
</select>
Run Code Online (Sandbox Code Playgroud)
我需要循环超过0.1,0.2,0.3直到达到5.0.
我应该添加什么才能让我这样做?
我指的是之前标记为正确答案的SO Coldfusion计算总和(循环?),但代码对我不起作用.
我试图从几个领域创建一个总计.但我收到的错误是"未定义变量xxx".这是因为我试图从循环中为所有记录追加值
<cfoutput>
<cfquery name="ActivityReceipts" dbtype="query">
SELECT
activity,
qty_approved,
location,
payment_amount,
shipping_cost,
handling_cost
FROM rc.RC1
WHERE id_number = '#Receipts.id_number#'
</cfquery>
<cfloop query="ActivityReceipts">
<tr>
<td style="text-align:left;">#ActivityReceipts.activity#</td>
<td style="text-align:left;">#ActivityReceipts.qty_approved#</td>
<td style="text-align:left;">#ActivityReceipts.location#</td>
<td style="text-align: right; padding-right: 80px;">#ActivityReceipts.payment_amount#</td>
</tr>
<cfset grandTotal = grandTotal + ( #ActivityReceipts.payment_amount# + #ActivityReceipts.handling_cost# + #ActivityReceipts.Shipping_cost# ) />
</cfloop>
<td>#grandTotal#</td>
</cfoutput>
Run Code Online (Sandbox Code Playgroud)
请注意,如果我将grandTotal变量设置行更改为
<cfset grandTotal = ( #ActivityReceipts.payment_amount# + #ActivityReceipts.handling_cost# + #ActivityReceipts.Shipping_cost# ) />
Run Code Online (Sandbox Code Playgroud)
它不会导致错误,但它也只是最后一行的总和,而不是所有的总和.
你会看到我很新.我想创建以下变量:
V1 =我的查询中的单词1V2 =我的查询中的单词2我可以静态地这样做:
<cfset V1=#qryGetWords["WordName"][1]#>
<cfset V2=#qryGetWords["WordName"][2]#>
<cfset V3=#qryGetWords["WordName"][3]#>
<cfset V4=#qryGetWords["WordName"][4]#>
Run Code Online (Sandbox Code Playgroud)
但我想动态地做.我已经看到了其他答案,但我也无法让他们工作.可以通过调整语法来完成以下任何工作吗?
<cfloop query="qryGetWords" index="i">
<cfset "V#i#" = #qryGetWords["WordName"]["i"]#>
</cfloop>
Run Code Online (Sandbox Code Playgroud)
我可以在cfloop中没有索引和查询吗?
考虑以下:
<cfoutput query="resources" group="type">
<h4>#type#</h4>
<cfoutput>
#name#
</cfoutput>
</cfoutput>
Run Code Online (Sandbox Code Playgroud)
resources.recordcount会给我记录的总数,但有没有一种优雅的方法来查找嵌套数据的记录数?例如
<cfoutput query="resources" group="type">
<h4>#type# (#noofrecords# of #resources.recordcount#)</h4>
<cfoutput>
#name#
</cfoutput>
</cfoutput>
Run Code Online (Sandbox Code Playgroud)
我可以用循环来做一些hacky,但是想知道是否有一种方法可以使用cfoutput组专门做到这一点.
我想创建一个函数,该函数将遍历任意查询并根据任意列名在另一个表中执行插入。
例如,这里的想法是输出
(data, data, data...)
(data, data, data...)
Run Code Online (Sandbox Code Playgroud)
最终,我将执行插入查询。现在,我只想输出行。
编辑:我不能只是INSERT/SELECT因为产品数据和开发数据在不同的服务器上。因此,我必须首先将产品服务器上的表中的数据收集到CF查询对象中,然后遍历它并插入开发服务器上的表中。
码:
<cffunction name="copyProdToDev">
<cfargument name="devDatasource" >
<cfargument name="prodDataSource" type="string">
<cfargument name="devTableName" type="string">
<cfargument name="prodTableName" type="string">
<cfargument name="dateColumnName" default="none">
<cfquery name="ProdData" datasource="#prodDatasource#" timeout="60">
SELECT *
FROM #prodTableName#
</cfquery>
<cfset columnNames = ProdData.getColumnNames()>
<cfset numColumns = ArrayLen(columnNames)>
<cfloop query="#ProdData#">
(
<cfloop index="colNumber" from="1" to="#ArrayLen(columnNames)-1#">
<cfoutput><dynamic column name for colNumber>,</cfoutput>
</cfloop>
<cfoutput><dynamic column name for numColumns></cfoutput>
)<br />
</cfloop>
</cffunction>
Run Code Online (Sandbox Code Playgroud) 我想根据传递给 cfdirectory 的过滤条件吐出略有不同的 html。
这是我的 cfml:
<cfdirectory
directory="#dirName#"
name="fileList"
action="list"
type="file"
filter="*.jpg|*.jpeg|*.png|*.gif|*.mp4"
>
<ul id="content">
<cfoutput>
<cfloop query="fileList">
<cfif filter NEQ '*.mp4'> // I guess this is not possible and is throwing the error
<li class="content image">
<img src="img/#name#" />
</li>
</cfif>
<cfelse>
<li class="video image">
<video controls="controls">
<source src="img/#name#" type="video/mp4">
</video>
</li>
</cfif>
</cfloop>
</cfoutput>
</ul>
Run Code Online (Sandbox Code Playgroud)
我认为我不能简单地访问filter内部cfif,但我不确定如何对其进行剥皮。它是否需要存储在循环外的变量中?
非常感谢任何帮助
我正在创建一个简单的电子邮件服务器状态页面,该页面调用两个不同的 CFC。
状态页要求:
输出类似于以下内容:
MyServerName - <up arrow>
MyServerName2 - <up arrow>
MyServerName3 - <up arrow>
MyServerName4 -<down arrow>
代码:
RetrieveEmailServers = APPLICATION.selectQueries.RetrieveEmailServers()
if (RetrieveEmailServers.recordCount) {
for(i = 1; i <= RetrieveEmailServers.recordCount(); i++) {
LOCAL.theDomains = RetrieveEmailServers.check_servers_domain[i];
LOCAL.theNames = RetrieveEmailServers.check_servers_name[i];
thread action="run" name="thread#i#" theDomains="#LOCAL.theDomains#" theNames="#LOCAL.theNames#" {
VARIABLES.theServers = APPLICATION.emailCheck.checkSMTPServer('#domains#',25,'','');
}
}
thread action="join" …Run Code Online (Sandbox Code Playgroud) cfloop ×10
coldfusion ×9
cfml ×2
cfquery ×2
anchor ×1
cfdirectory ×1
cfoutput ×1
cfthread ×1
coldfusion-9 ×1
html ×1
loops ×1
lucee ×1
sql ×1
sql-server ×1
variables ×1